问题描述
我一直在 matplotlib 中寻找新的线条样式,唯一可用的线条样式是 ["-", "--", "-.", ":",].(样式选项 ['', ' ', 'None',] 不算在内,因为它们只是隐藏了线条.)
在 Matplotlib pyplot 中真的只有 4 种线条样式吗?是否有任何扩展可以添加更多线条样式?有没有办法自定义线条样式?像这样的三个字符线样式怎么样:
- '--.': 破折号 破折号
- '-..': dash dot dot
- '...': dot dot dot(空格)
- 'xxx':x 在一行中
- '/':锯齿形即'////'
- '::': 平行点,即 ::::::
这些只是扩展线条样式范围的一些想法.
您可以使用 dashes
kwarg 来设置自定义虚线样式.
来自
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.
You can use the dashes
kwarg to set custom dash styles.
From the docs:
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')
这篇关于真的只有 4 种 Matplotlib 线条样式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!