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

Histogram in 3.4.0 #1257

Closed
sursu opened this issue Nov 3, 2018 · 7 comments · Fixed by #1268
Closed

Histogram in 3.4.0 #1257

sursu opened this issue Nov 3, 2018 · 7 comments · Fixed by #1268
Labels
bug something broken
Milestone

Comments

@sursu
Copy link
Contributor

sursu commented Nov 3, 2018

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.

@jonmmease
Copy link
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.

@jonmmease jonmmease added bug something broken plotly.js labels Nov 3, 2018
@sursu
Copy link
Contributor Author

sursu commented Nov 3, 2018

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?

@jonmmease
Copy link
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>'

@jonmmease
Copy link
Contributor

Tracking upstream fix in plotly/plotly.js#3211

@jonmmease jonmmease added this to the v3.4.1 milestone Nov 6, 2018
@jonmmease
Copy link
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!

@sursu
Copy link
Contributor Author

sursu commented Nov 7, 2018

@jonmmease Yes. Issue fixed.

Thank you! 👍

@jonmmease
Copy link
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
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants