Skip to content

Histogram in 3.4.0 #1257

Closed
Closed

Description

@sursu

Hi, I think there is an issue with FigureWidget in 3.4.0. The behavior I will describe below did not exist in 3.3.0.

I use Jupyter Lab.

import numpy as np

import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
# Simulations
n = 100
A = np.arange(1,n+1, dtype=float).reshape(n,1)**(-2)
X = 2*np.random.randint(2, size=(n,1000000))-1

Now, this works:
iplot([go.Histogram(x=np.sum(A*X,axis=0))])

newplot

This does not work (even though it did before):

# Histogram for S_n
fig = go.FigureWidget()
fig.add_histogram(x=np.sum(A*X,axis=0),
                  opacity=0.75,
                  histnorm='probability density')
fig['layout'].update(title='Distribution of $S_{'+str(n)+'}$', 
                  showlegend=False, height=700)
fig

newplot 1

Also, note that part of the title is not displayed.

Activity

  1. jonmmease commented on Nov 3, 2018

    @jonmmease
    Contributor

    Hi @sursu ,

    Thanks a lot for taking the time to report this, and for providing the reproducible example. It looks like you caught a regression in plotly.js 1.42. I've opened a corresponding issue over there plotly/plotly.js#3210. In the meantime, you can work around the issue by converting your histogram x value to a list. e.g.

    fig.add_histogram(x=np.sum(A*X,axis=0).tolist(), ...)

    The reason this only shows up in FigureWidget is because all of the other plotting approaches automatically convert numpy arrays to lists internally. For efficiency FigureWidget preserves numpy arrays as binary buffers and converts them to JavaScript TypedArrays in the browser. And this regression is in the handling of TypedArrays by plotly.js.

  2. added
    bug
    on Nov 3, 2018
  3. sursu commented on Nov 3, 2018

    @sursu
    ContributorAuthor

    I hope the fix will preserve the efficiency of FigureWidget.

    What do I do wrong in the second plot that only the LaTeX expression is displayed as title?

  4. jonmmease commented on Nov 3, 2018

    @jonmmease
    Contributor

    Hi @sursu, yes the fix will preserve FigureWidget's efficiency 🙂

    As for the situation with your title, at this point LaTeX can't be mixed with non-latex. So the $signs need to be the first and last characters of your string. In this case you could set your title string to something like '$\\text{Distribution of }S_{10}$' to get what you want. Or, if all you need is italic text and subscripts you could do this in HTML as 'Distribution of <i>S</i><sub>10</sub>'

  5. jonmmease commented on Nov 5, 2018

    @jonmmease
    Contributor

    Tracking upstream fix in plotly/plotly.js#3211

  6. added this to the v3.4.1 milestone on Nov 6, 2018
  7. jonmmease commented on Nov 7, 2018

    @jonmmease
    Contributor

    Closed by #1268. @sursu, could you give the 3.4.1 release candidate a try and confirm that it fixes the issue for you? Installation instructions for the release candidate at https://github.com/plotly/plotly.py/tree/release_3.4.1

    Thanks again for taking the time to to report this!

  8. sursu commented on Nov 7, 2018

    @sursu
    ContributorAuthor

    @jonmmease Yes. Issue fixed.

    Thank you! 👍

  9. jonmmease commented on Nov 7, 2018

    @jonmmease
    Contributor

    Great! Thanks for giving the release candidate a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions