Python matplotlib 阶跃函数中的线型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15188005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linestyle in matplotlib step function
提问by user2061207
Is it possible to set the linestyle in a matplotlib step function to dashed, dotted, etc.?
是否可以将 matplotlib 步骤函数中的线型设置为虚线、虚线等?
I've tried:
我试过了:
step(x, linestyle='--'),
step(x, '--')
But it did not help.
但它没有帮助。
采纳答案by tacaswell
As of mpl 1.3.0 this is fixed upstream
从 mpl 1.3.0 开始,这已在上游修复
You have to come at it a bit sideways as stepseems to ignore linestyle. If you look at what stepis doing underneath, it is just a thin wrapper for plot.
你必须稍微侧身一下,因为它step似乎忽略了linestyle。如果你看看step下面在做什么,它只是情节的一个薄包装。
You can do what you want by talking to plotdirectly:
您可以通过plot直接交谈来做您想做的事:
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']are the valid values for drawstyleand control where the step is drawn.
['steps', 'steps-pre', 'steps-mid', 'steps-post']drawstyle是绘制步骤的位置的有效值和控制。
Pullrequest 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].
由这个问题产生的拉取请求,我个人认为这是一个错误。[编辑:这已被拉入 master 并应出现在 v1.3.0]。

