Skip to content

[Bug]: agg.path.chunksize leaves gaps in lines at chunk boundaries #32641

Open

Description

@yqtian-se

Bug summary

With agg.path.chunksize set, a long line is drawn with a gap at every chunk boundary: two segments are missing each time. The docs say the line is split into several lines of at most chunksize vertices, not that points are dropped. The rc docs warn about "minor artifacts", but I would not expect whole segments to go missing.

Code for reproduction

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np


def render(chunksize):
    with mpl.rc_context({"agg.path.chunksize": chunksize}):
        fig, ax = plt.subplots()
        x = np.arange(200)
        ax.plot(x, x % 2, lw=1, solid_joinstyle="round", solid_capstyle="round",
                antialiased=False, color="k")
        ax.set_axis_off()
        fig.canvas.draw()
        img = np.asarray(fig.canvas.buffer_rgba()).copy()
        fig.savefig(f"chunksize_{chunksize}.png")
        plt.close(fig)
    return img


print("pixels differing:", int((render(0) != render(150)).any(-1).sum()))

Actual outcome

pixels differing: 961. chunksize_150.png has a visible gap in the zigzag where the line is split.

main_chunksize_150

Expected outcome

No gaps. With round caps and joins and antialiasing off, the chunked line should look the same as

fixed_chunksize_150

the unchunked one (0 pixels differing).

Additional information

In RendererAgg.draw_path the chunk ends are computed as i1[:-1] = i0[1:] - 1 and used as an exclusive slice end. So vertex i0[k+1] - 1 is in no chunk, and the segments on both sides of it are not drawn. Letting consecutive chunks share their boundary vertex fixes it; I can open a PR.

The same output with the released 3.10.8.

Operating system

Linux (Ubuntu on WSL2)

Matplotlib Version

3.12.0.dev943+gc21a3923e

Matplotlib Backend

agg

Python version

3.14.10

Jupyter version

No response

Installation

git checkout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions