# Incorrect rendering with many subplots

**URL:** <https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647>\
**Category:** 📊 Plotly Python\
**Created:** [December 30, 2021, 7:24am UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647 "2021-12-30T07:24:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![naten7k](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@naten7k](https://community.plotly.com/u/naten7k)\
**Post date:** [December 30, 2021, 7:25am UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/1 "2021-12-30T07:25:00Z")

</div>

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

```auto
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:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/0/3/036eeb2deca5f2b12e17f421bd3dc5e500d34fa3.png)

However, when I look at the file with 25 subplots, it renders like this:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/1/0/1054893101f618f4140fbd6ba892a281ca8f4d04.png)

Am I doing something wrong? Thanks very much in advance, all help extremely appreciated!

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [December 30, 2021, 7:02pm UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/2 "2021-12-30T19:02:12Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![naten7k](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@naten7k](https://community.plotly.com/u/naten7k)\
**Post date:** [December 30, 2021, 7:19pm UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/3 "2021-12-30T19:19:49Z")

</div>

As I noted in my post, I did not observe this issue in chrome, just in firefox (I’m running 89.0.2, 64-bit). Thanks!

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [December 30, 2021, 7:43pm UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/4 "2021-12-30T19:43:51Z")

</div>

Sorry. I didn’t read carefully ☹

---

<div class="post-metadata">

**Author:** ![naten7k](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@naten7k](https://community.plotly.com/u/naten7k)\
**Post date:** [December 30, 2021, 7:46pm UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/5 "2021-12-30T19:46:36Z")

</div>

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 :).

---

<div class="post-metadata">

**Author:** ![naten7k](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@naten7k](https://community.plotly.com/u/naten7k)\
**Post date:** [December 30, 2021, 9:41pm UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/6 "2021-12-30T21:41:49Z")

</div>

@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.

100 subplots:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/4/f/4f76ecb8685ef7accc8df55415f635764cd39c7e.png)

80 subplots:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/4/2/42eb7ac1189702f1ef32dfb8aefe105213c277c6.png)

60 subplots:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/2/4/245f277aeff2a76a4209578d72b621b5641d09b0.png)

40 subplots:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/0/8/081e9de4e7d05322f9cbfdac33e37dffc46dc83c.png)

---

<div class="post-metadata">

**Author:** ![naten7k](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@naten7k](https://community.plotly.com/u/naten7k)\
**Post date:** [January 6, 2022, 10:55pm UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/7 "2022-01-06T22:55:32Z")

</div>

^ bump? i would _really_ appreciate it if anyone could even give me an area to start digging here about where the issue might be. thanks so much!

---

<div class="post-metadata">

**Author:** ![naten7k](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@naten7k](https://community.plotly.com/u/naten7k)\
**Post date:** [January 16, 2022, 2:53am UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/8 "2022-01-16T02:53:21Z")

</div>

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:

```auto
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")

```

For 5 subplots, everything looks fine:

 ![5_subplots](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/3/f/3fbb43ae2bb9dfbd9540b8b4e52eb4a97b9bf0d6.png)

For 6+ subplots, traces are missing after the first 5 subplots, and the existing traces dont stay within their plotting bounds.

 ![6_subplots](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/7/c/7c5d23d61542a734f307cb5c4698b9d058da6b67.png)

---

<div class="post-metadata">

**Author:** ![naten7k](https://avatars.discourse-cdn.com/v4/letter/n/c2a13f/32.png) [@naten7k](https://community.plotly.com/u/naten7k)\
**Post date:** [January 16, 2022, 9:48pm UTC](https://community.plotly.com/t/incorrect-rendering-with-many-subplots/59647/9 "2022-01-16T21:48:04Z")

</div>

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](https://community.plotly.com/t/scattergl-markers-not-displaying/19553)  
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?
