user2968773
user2968773

Reputation: 73

Matplotlib set_drawstyle doesn't work

I noticed something weird. When I make a link chart with drawstyle parameter, it works. For example

import matplotlib.pyplot as plt

x = np.linspace(10, 24, 10)
y = np.random.randn(10)

fig, ax = plt.subplots() 
ax.plot(x, y, drawstyle="steps")

However, if I want to set it with, say,

ax.lines[0].set_drawstyle('steps') 

It does not work at all. Instead a line without steps is shown.

Any clues?

Upvotes: 2

Views: 1120

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339200

There is now a fix to this bug on its way.

Until this finds its way into the next release of matplotlib, you may apply it manually. The solution is to add line._invalidx = True to force the line being recached.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(10, 24, 10)
y = np.random.randn(10)

fig, ax = plt.subplots() 
line, = ax.plot(x, y)
line.set_drawstyle("steps-pre") 
line._invalidx = True

plt.show()

Upvotes: 3

Related Questions