阅读背景:

Matplotlib set_drawstyle行不通

来源:互联网 

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

我注意到一些奇怪的。当我用drawstyle参数创建一个链接图时,它可以工作。例如

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?

有线索吗?

1 个解决方案

#1


2  

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

现在这个bug已经得到了修复。

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.

在它进入matplotlib的下一个版本之前,您可以手工应用它。解决方案是添加line。使这条线被重新校准。

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

分享到: