-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement (DataFrame|Series).plot.hist in plotly #1999
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1999 +/- ##
==========================================
+ Coverage 94.53% 94.55% +0.01%
==========================================
Files 50 50
Lines 10995 11086 +91
==========================================
+ Hits 10394 10482 +88
- Misses 601 604 +3
Continue to review full report at Codecov.
|
4bb1a2b
to
0eef796
Compare
0eef796
to
71e13d5
Compare
77566f8
to
63f23b8
Compare
@@ -338,31 +344,41 @@ def _get_plot_backend(backend=None): | |||
|
|||
KoalasPlotAccessor._backends["matplotlib"] = module | |||
|
|||
if backend == "plotly": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I avoided to monkey patch plotly. I will need to refactor codes here in another PR .. here needs some refactoring.
@@ -16,7 +16,7 @@ | |||
|
|||
from distutils.version import LooseVersion | |||
|
|||
import matplotlib | |||
import matplotlib as mat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is due to the conflict when you import, from databricks.koalas.plot import matplotlib
As a module databricks.koalas.plot.matplotlib
vs matplotlib
library imported at databricks.koalas.plot
. I will fix it back in the next PR that refactors.
63f23b8
to
7014607
Compare
41e542f
to
4ae387a
Compare
9575d6d
to
42a04a2
Compare
42a04a2
to
4d09feb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good.
def plot(data, kind, **kwargs): | ||
import plotly | ||
|
||
return plot | ||
# Koalas specific plots | ||
if kind == "pie": | ||
return plot_pie(data, **kwargs) | ||
if kind == "hist": | ||
# Note that here data is a Koalas DataFrame or Series unlike other type of plots. | ||
return plot_histogram(data, **kwargs) | ||
|
||
# Other plots. | ||
return plotly.plot(data, kind, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 👍
This PR implements Series.plot.box with plotly. Note that DataFrame.plot.box is not already supported in Koalas yet. This can be tested via the link: https://mybinder.org/v2/gh/HyukjinKwon/koalas/plot-box-ser?filepath=docs%2Fsource%2Fgetting_started%2F10min.ipynb Note that you should manually install plotly to test with mybinder above: ``` %%bash pip install plotly ``` Example: ```python # Koalas from databricks import koalas as ks ks.options.plotting.backend = "plotly" kdf = ks.DataFrame({"a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 50],}, index=[0, 1, 3, 5, 6, 8, 9, 9, 9, 10, 10]) kdf.a.plot.box() # pandas import pandas as pd pd.options.plotting.backend = "plotly" pdf = pd.DataFrame({"a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 50],}, index=[0, 1, 3, 5, 6, 8, 9, 9, 9, 10, 10]) pdf.a.plot.box() ``` ![Screen Shot 2021-01-14 at 6 56 19 PM](https://user-images.githubusercontent.com/6477701/104575700-acdc4080-569a-11eb-8d55-0ac3db800ddd.png) ![Screen Shot 2021-01-14 at 6 56 24 PM](https://user-images.githubusercontent.com/6477701/104575705-ad74d700-569a-11eb-9b7c-a37e04f77ec7.png) For the same reason as #1999, the output is slightly different from pandas'. I referred to "Box Plot With Precomputed Quartiles" in https://plotly.com/python/box-plots/
This PR implements
(DataFrame|Series).plot.hist
in plotly:This can be tested via: https://mybinder.org/v2/gh/HyukjinKwon/koalas/plotly-histogram?filepath=docs%2Fsource%2Fgetting_started%2F10min.ipynb
Example:
NOTE that the output is a bit different because: