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
222 views
in Technique[技术] by (71.8m points)

python - Are there really only 4 Matplotlib Line Styles?

I've been looking for new line styles in matplotlib, and the only line styles available are ["-", "--", "-.", ":",]. (The style options ['', ' ', 'None',] don't count because they just hide the lines.)

Are there really only 4 line styles in Matplotlib pyplot? Are there any extensions that add further line styles? Is there a way to customise line styles? How about some three character line styles like:

  • '--.': dash dash dot
  • '-..': dash dot dot
  • '...': dot dot dot (space)
  • 'xxx': x's in a line
  • '/': Zig zags ie '////'
  • '::': parrallel dots, ie :::::

These are just some ideas to expand the range of line styles.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can use the dashes kwarg to set custom dash styles.

From the docs:

Set the dash sequence, sequence of dashes with on off ink in points. If seq is empty or if seq = (None, None), the linestyle will be set to solid.

Here's some examples based on a few of your suggestions. Obviously there are many more ways you could customise this.

import matplotlib.pyplot as plt

fig,ax = plt.subplots(1)

# 3 dots then space
ax.plot(range(10), range(10),     dashes=[3,6,3,6,3,18],  lw=3,c='b')

# dash dash dot
ax.plot(range(10), range(0,20,2), dashes=[12,6,12,6,3,6], lw=3,c='r')

# dash dot dot
ax.plot(range(10), range(0,30,3), dashes=[12,6,3,6,3,6],  lw=3,c='g')

enter image description here


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

...