It seems like if I go from 20-25 subplots, a weird rendering problem crops up where the traces are too big and not restricted to the plots. This occurs in firefox, but not in google chrome (although chrome crashes when attempting to load 40 subplots, whereas firefox does not). Here’s a minimal example
import numpy as np
import plotly.graph_objects as go
import plotly.subplots as ps
y = np.random.rand(1000)
for num_subplots in [20, 25]:
fig = ps.make_subplots(rows=num_subplots, cols=1)
fig.update_layout(height=200 * num_subplots, showlegend=False)
for i in range(num_subplots):
scatter = go.Scattergl(x=np.arange(len(y)), y=y, mode="lines", line=dict(color="#000000"))
fig.add_trace(scatter, row=i + 1, col=1)
with open(f"{num_subplots}_subplots.html", "w") as f:
f.write(fig.to_html(full_html=False)) # same result for `full_html=True`
When I run this with 20 subplots, things render properly:
@naten7k
I cannot reproduce your issue. I have Chrome Version 96.0.4664.110 (Official Build) (64-bit), and it displays nice subplots, in the html file with 20 or 25 subplots.
no problem! this might be a weird firefox issue, which given firefox’s user share isnt worth figuring out. but figured i’d bring it up, since (a) its a pretty odd behavior and (b) firefox is my default browser :).
@empet The plot thickens! This does happen in chrome, but you need more plots to get it to happen, and the behavior is slightly different (plots dont have a rightwards offset, but are incorrectly scaled vertically). Furthermore, the incorrectness of the vertical scaling scales with the number of subplots! See plots below.
Furthermore, it also depends on the height per subplot. If you increase the height per subplot to 800, then this problem shows up in chrome at 20 subplots, and in firefox at 10 subplots.
I’m not sure how plotly.graph_objs.Figure.write_image() works, but it seems to suffer from a possibly-related issue, where for more than N subplots, the first N plotted traces not constrained to the plot area and the remainder of the traces dont seem to be rendered! N seems to depend on plot height, such that this problem only crops up when (number of subplots * subplot height) > 4000. Here’s a minimal example:
import numpy as np
import plotly.graph_objects as go
import plotly.subplots as ps
y = np.random.rand(1000)
for num_subplots in range(2,10):
fig = ps.make_subplots(rows=num_subplots, cols=1)
fig.update_layout(height=800 * num_subplots, showlegend=False)
for i in range(num_subplots):
scatter = go.Scattergl(x=np.arange(len(y)), y=y, mode="lines", line=dict(color="#000000"))
fig.add_trace(scatter, row=i + 1, col=1)
fig.write_image(f"{num_subplots}_subplots.png")
Oof, I ought to understand that ‘edit post’ and ‘reply’ are not the same, please ignore my stupid edit history on the above post.
One more note - this issue doesnt seem to happen for graph_objs.Scatter, just graph_objs.Scattergl objects. I unfortunately can’t just switch to Scatter though because it’s order-of-magnitude slower for the quantity of data I’m trying to render.
I also just found this thread which suggests a limit on the number of GL instances in a window: ScatterGL markers not displaying
However, if I’m understanding correctly, it seems that what I’m doing shouldnt hit that limit since they’re subplots and therefore part of the same GL instance? @chriddyp am I interpreting that correctly?