You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Enabling the line on a previously drawn step plot connects the markers diagonally #32695
Draw a post-step plot with markers only, then call set_linestyle("-") and redraw. The markers stay in place, but the stroke connects them diagonally even though get_drawstyle() still returns "steps-post".
Code for reproduction
importmatplotlib.pyplotaspltfig, ax=plt.subplots()
line, =ax.step([0, 1, 2], [0, 1, 0], where="post", marker="o", linestyle="None")
fig.canvas.draw() # Draw once with only the markers visible.line.set_linestyle("-")
fig.canvas.draw()
print(line.get_drawstyle())
print(line.get_path().vertices.tolist())
fig.savefig("step-redraw.png")
Actual outcome
The PNG shows two diagonal segments forming a peak. The reported draw style and path are:
steps-post
[[0.0, 0.0], [1.0, 1.0], [2.0, 0.0]]
Expected outcome
Enabling the stroke should produce the same staircase as passing linestyle="-" to the original ax.step() call. The stroke should pass through (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 0), with markers at the three input samples.
recache() overwrites self._path with the non-step path, but _setattr_cm only restores _drawstyle and _transformed_path, so self._path stays as the non-step path afterwards. If the line was already drawn in that call, the cached step _transformed_path gets restored and hides the problem. In this report the line was not drawn on the first draw (linestyle="None"), so the cache is empty and the next draw rebuilds it from the wrong _path.
This also affects the normal case: after any draw, get_path() returns the non-step path even when linestyle="-" from the start:
I can reproduce both on 3.11.2 as well, so this is not a recent regression.
Adding _path=self._path to the _setattr_cm call fixes both cases locally. A cleaner alternative might be to compute the marker positions directly from self._xy without calling recache() at all.
I'm happy to open a PR with a fix and a regression test. Let me know if either approach is preferred.
Activity
RaghavRD commentedon Nov 30, 2026
I looked into this and I think I've found the root cause.
In
Line2D.draw(), markers are drawn ignoring the drawstyle by temporarily switching to"default"and callingrecache():recache()overwritesself._pathwith the non-step path, but_setattr_cmonly restores_drawstyleand_transformed_path, soself._pathstays as the non-step path afterwards. If the line was already drawn in that call, the cached step_transformed_pathgets restored and hides the problem. In this report the line was not drawn on the first draw (linestyle="None"), so the cache is empty and the next draw rebuilds it from the wrong_path.This also affects the normal case: after any draw,
get_path()returns the non-step path even whenlinestyle="-"from the start:I can reproduce both on 3.11.2 as well, so this is not a recent regression.
Adding
_path=self._pathto the_setattr_cmcall fixes both cases locally. A cleaner alternative might be to compute the marker positions directly fromself._xywithout callingrecache()at all.I'm happy to open a PR with a fix and a regression test. Let me know if either approach is preferred.