Closed
Description
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()
[This is reproduced with matplotlib 2.1.2 on python 2.7 (64bit), windows 8.1 (64bit), both with TkAgg and Qt4Agg]
Metadata
Metadata
Assignees
Labels
No labels