8000 line.set_drawstyle fails to produce step-like line · Issue #10338 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
line.set_drawstyle fails to produce step-like line #10338
Closed
@ImportanceOfBeingErnest

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()

image

[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

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

      0