Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line.set_drawstyle fails to produce step-like line #10338

Closed
ImportanceOfBeingErnest opened this issue Jan 28, 2018 · 1 comment · Fixed by #10340
Closed

line.set_drawstyle fails to produce step-like line #10338

ImportanceOfBeingErnest opened this issue Jan 28, 2018 · 1 comment · Fixed by #10340
Milestone

Comments

@ImportanceOfBeingErnest
Copy link
Member

Using the .set_drawstyle method of a matplotlib.lines.Line2D fails if this line has been produced via plt.plot(). If the line is produced via plt.Line2D and subsequently added to the canvas, the output is as expected.

The following demonstrates this. We would expect to see the same step-like line in both subplots, but the right subplot, showing a line produced via plot, ignores its drawstyle.

import matplotlib.pyplot as plt
import numpy as np; np.random.seed(1)

x = np.linspace(0,1,20)
y = np.random.rand(len(x))

fig, (ax,ax2) = plt.subplots(ncols=2, figsize=(6,2.8))

line = plt.Line2D(x,y)
ax.add_artist(line)
line.set_drawstyle("steps-pre")    # <-- this gives the desired step function

line2, = ax2.plot(x,y)  
line2.set_drawstyle("steps-pre")  # <-- this fails

plt.show()

image

[This is reproduced with matplotlib 2.1.2 on python 2.7 (64bit), windows 8.1 (64bit), both with TkAgg and Qt4Agg]

@anntzer
Copy link
Contributor

anntzer commented Jan 28, 2018

Line2D.set_drawstyle needs to add either self._invalidx = True or self._invalidy = True to trigger a recache of the path; that fixes the issue. (Actually this will also cause a useless round through the unit machinery because it's not actually the x or y values that have become invalid, but right now there's no way to say "it's the drawstyle that has become invalid" (well, perhaps add a new flag).

ImportanceOfBeingErnest added a commit to ImportanceOfBeingErnest/matplotlib that referenced this issue Jan 28, 2018
Invalidate path on set_drawstyle to recache path, such that the new drawstyle is actually applied.
Fixes matplotlib#10338
@QuLogic QuLogic added this to the v2.2 milestone Jan 29, 2018
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants