Skip to content

[Bug]: Lines between points are invisible when there are more than 7 subfigures per row #28893

Closed

Description

@vealocia

Bug summary

When there are more than 7 sub figures per row, the line between points will be invisible for the last several subfigs.

Code for reproduction

import matplotlib.pyplot as plt

subfig_size = (16, 9)

num_subfigs = 10
fig, axes = plt.subplots(1, num_subfigs, figsize=(num_subfigs * subfig_size[0], 1 * subfig_size[1]), dpi=300)
for j in range(num_subfigs):
    xs = list(range(10))
    ax = axes[j]
    
    ax.plot(xs, xs, marker='x', label=f"test", linewidth=3, markersize=10)

plt.savefig('test.jpg')

Actual outcome

test

Expected outcome

Line should be visible!

Additional information

What are the conditions under which this bug happens? input parameters, edge cases, etc?

  • matplotlib==3.9.2
    Has this worked in earlier versions?
  • Tried 3.5.0, but still not works

Operating system

Ubuntu

Matplotlib Version

3.9.2

Matplotlib Backend

qtagg

Python version

3.10.9

Jupyter version

6.5.2

Installation

pip

Activity

  1. ksunden commented on Sep 26, 2024

    @ksunden
    Member

    This is likely not due to the number of subfigs, but rather the number of pixels.

    Agg (the renderer we most commonly use) has some fairly deep fundamental limitations when it comes to rendering on large canvases, which have some complicated relationships with how various elements are drawn (hence why markers and text still show up, but lines do not)

    You are making a figure that is 160 inches wide at 300 dpi. I expect that if you lower the DPI, it will work for more figures, but regardless, we just simply cannot render it with Agg.

    Agg has a limit of 2**15 = 32,768 pixels in each dimension. In your example, that is exceeded by the 7th subfigure (716300 = 33,600), hence why it happens then.

    Unfortunately it is unlikely to be changed any time soon, as it is pretty deeply ingrained and therefore hard to change.

    Solutions may include, and which one is appropriate will vary based on specific usecases:

    • smaller figures
    • lower resolution (does it need to be 300 DPI)
    • multiple figures (does it need to be one figure, can it be composed in an external image editor?)
    • Using a cairo based backend?
      • I have not tried this recently, but know the specific limitation is in Agg, so other renderers may not be affected.
      • There are likely some size limitation still, not sure if they are the same size though.

    See also:

    #26751

    #26368

    Probably more, these are just the more recent ones I found of effectively the same thing

  2. vealocia commented on Sep 26, 2024

    @vealocia
    Author

    Thanks for your quick reply! I will divide and draw each subfigure separately!

  3. added this to the v3.10.0 milestone on Oct 8, 2024
  4. added a commit that references this issue on Oct 10, 2024
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions