Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

python - Linestyle in matplotlib step function

Is it possible to set the linestyle in a matplotlib step function to dashed, dotted, etc.?

I've tried:

step(x, linestyle='--'), 
step(x, '--')

But it did not help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As of mpl 1.3.0 this is fixed upstream


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.

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

example

['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].


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...