Skip to content
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.kde with Plotly #2028

Merged
merged 2 commits into from
Feb 3, 2021

Conversation

HyukjinKwon
Copy link
Member

@HyukjinKwon HyukjinKwon commented Feb 1, 2021

This PR implements (DataFrame|Series).plot.kde with Plotly:

Can be tested here:

http://mybinder.org/v2/gh/hyukjinkwon/koalas/plotly-kde?filepath=docs%2Fsource%2Fgetting_started%2F10min.ipynb

matplotlib:

import databricks.koalas as ks
ks.options.plotting.backend = "matplotlib"
kdf = ks.DataFrame({
    'a': [1, 2, 2.5, 3, 3.5, 4, 5],
    'b': [1, 2, 3, 4, 5, 6, 7],
    'c': [0.5, 1, 1.5, 2, 2.5, 3, 3.5]})
kdf.plot.kde(bw_method=3).figure.savefig("fig1_mat.png")
kdf.a.plot.kde(bw_method=3).figure.savefig("fig2_mat.png")

fig1_mat
fig2_mat

plotly

import databricks.koalas as ks
ks.options.plotting.backend = "plotly"
kdf = ks.DataFrame({
    'a': [1, 2, 2.5, 3, 3.5, 4, 5],
    'b': [1, 2, 3, 4, 5, 6, 7],
    'c': [0.5, 1, 1.5, 2, 2.5, 3, 3.5]})
kdf.plot.kde(bw_method=3).write_image("fig1.png")
kdf.a.plot.kde(bw_method=3).write_image("fig2.png")

fig1
fig2

@codecov-io
Copy link

codecov-io commented Feb 1, 2021

Codecov Report

Merging #2028 (7db02e4) into master (5e28195) will decrease coverage by 4.02%.
The diff coverage is 32.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2028      +/-   ##
==========================================
- Coverage   94.59%   90.57%   -4.03%     
==========================================
  Files          50       50              
  Lines       11277    11210      -67     
==========================================
- Hits        10668    10153     -515     
- Misses        609     1057     +448     
Impacted Files Coverage Δ
databricks/koalas/plot/plotly.py 9.47% <5.26%> (-86.58%) ⬇️
...bricks/koalas/tests/plot/test_frame_plot_plotly.py 23.33% <14.28%> (-76.67%) ⬇️
...ricks/koalas/tests/plot/test_series_plot_plotly.py 26.92% <14.28%> (-71.14%) ⬇️
databricks/koalas/plot/core.py 91.49% <72.22%> (-1.04%) ⬇️
databricks/koalas/plot/matplotlib.py 91.27% <100.00%> (-0.58%) ⬇️
databricks/koalas/usage_logging/__init__.py 25.66% <0.00%> (-66.65%) ⬇️
databricks/koalas/usage_logging/usage_logger.py 47.82% <0.00%> (-52.18%) ⬇️
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e28195...7db02e4. Read the comment docs.

sample_range = max_val - min_val
ind = np.linspace(min_val - 0.5 * sample_range, max_val + 0.5 * sample_range, 1000,)
elif is_integer(ind):
min_val, max_val = sdf.select(F.min(sdf.columns[-1]), F.max(sdf.columns[-1])).first()

sample_range = min_val - max_val
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug BTW. it had to be max_val - min_val

@staticmethod
def get_ind(sdf, ind):
# 'sdf' is a Spark DataFrame that selects one column.
def calc_min_max():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a logic to get the max/min from multiple columns

@HyukjinKwon HyukjinKwon force-pushed the plotly-kde branch 3 times, most recently from 2586c0f to 4e34196 Compare February 2, 2021 03:56
Copy link
Collaborator

@ueshin ueshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

databricks/koalas/plot/core.py Outdated Show resolved Hide resolved
@HyukjinKwon HyukjinKwon merged commit afdf6b2 into databricks:master Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants