matplotlib步骤功能中的线型 [英] Linestyle in matplotlib step function
问题描述
是否可以将matplotlib步骤功能中的线型设置为虚线,点线等?
Is it possible to set the linestyle in a matplotlib step function to dashed, dotted, etc.?
我尝试过:
step(x, linestyle='--'),
step(x, '--')
但这没有帮助.
推荐答案
从mpl 1.3.0开始,此问题已在上游固定
As of mpl 1.3.0 this is fixed upstream
由于step
似乎忽略了linestyle
,因此您必须稍作调整.如果您查看step
在下面的操作,它只是用于绘图的薄包装.
You have to come at it a bit sideways as step
seems to ignore linestyle
. If you look at what step
is doing underneath, it is just a thin wrapper for plot.
您可以通过直接与plot
交谈来做您想做的事情:
You can do what you want by talking to plot
directly:
import matplotlib.pyplot as plt
plt.plot(range(5), range(5), linestyle='--', drawstyle='steps')
plt.plot(range(5), range(5)[::-1], linestyle=':', drawstyle='steps')
plt.xlim([-1, 5])
plt.ylim([-1, 5])
['steps', 'steps-pre', 'steps-mid', 'steps-post']
是drawstyle
的有效值,并控制绘制步骤的位置.
['steps', 'steps-pre', 'steps-mid', 'steps-post']
are the valid values for drawstyle
and control where the step is drawn.
拉请求,我个人认为这是一个错误.
Pull request resulting from this question, I personally think this is a bug. [edit: this has been pulled into master and should show up in v1.3.0].
这篇关于matplotlib步骤功能中的线型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!