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))])

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

Also, note that part of the title is not displayed.
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 https://github.com/plotly/plotly.js/issues/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.
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?
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>'
Tracking upstream fix in https://github.com/plotly/plotly.js/pull/3211
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!
@jonmmease Yes. Issue fixed.
Thank you! :+1:
Great! Thanks for giving the release candidate a try