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

distplot: only compute traces that will be shown #2730

Merged
merged 1 commit into from
Sep 3, 2020
Merged

distplot: only compute traces that will be shown #2730

merged 1 commit into from
Sep 3, 2020

Conversation

akbo
Copy link
Contributor

@akbo akbo commented Aug 28, 2020

In this pull request I make a small change to ff.create_distplot. ff.create_distplot produces a figure showing the distribution of some data. It can create three traces (histogram, kernel density estimation (KDE) and rug) and it has switches that let users select, which of the aforementioned traces to include in the resulting figure.

Independent of the user choice (boolean parameters: show_hist, show_curve and show_rug), it will compute all three traces whether they will be included in the resulting figure or not. I changed the code so that only the traces that will be included in the resulting figure get computed.

This will make the function more efficient in situations where a user doesn't need all three traces.

Also (this is my use case), it allows one corner case that currently doesn't work: The function currently doesn't support being called with a dataset (hist_data parameter) that only contains a single entry. What happens in this case is that scipy throws an exception when trying to compute the KDE. However, in some use cases, there is no need for a KDE (show_curve=False). It should be possible to create a distplot with a single-entry dataset without a KDE.

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or
    modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.

@nicolaskruchten
Copy link
Contributor

Seems straightforward enough! Thanks :)

@nicolaskruchten nicolaskruchten merged commit ace6783 into plotly:master Sep 3, 2020
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.

2 participants