Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否只有4种Matplotlib线条样式?_Python_Matplotlib_Plot - Fatal编程技术网

Python 是否只有4种Matplotlib线条样式?

Python 是否只有4种Matplotlib线条样式?,python,matplotlib,plot,Python,Matplotlib,Plot,我一直在matplotlib中寻找新的线条样式,唯一可用的线条样式是[“-”、“-”、“-”、“-.”、“:”、]。(样式选项['','无',]不起作用,因为它们只是隐藏线条。) Matplotlib pyplot中真的只有4种线条样式吗?是否有任何扩展可以添加更多的线型?有没有办法定制线条样式?以下三种字符行样式如何: “--.”:破折号 “-…”:虚线点 “…”:点(空格) “xxx”:x在一行中 “\/”:锯齿形,即“\/\/\/\/” “:”:平行点,即: 这些只是一些扩大线条样式范

我一直在matplotlib中寻找新的线条样式,唯一可用的线条样式是[“-”、“-”、“-”、“-.”、“:”、]。(样式选项['','无',]不起作用,因为它们只是隐藏线条。)

Matplotlib pyplot中真的只有4种线条样式吗?是否有任何扩展可以添加更多的线型?有没有办法定制线条样式?以下三种字符行样式如何:

  • “--.”:破折号
  • “-…”:虚线点
  • “…”:点(空格)
  • “xxx”:x在一行中
  • “\/”:锯齿形,即“\/\/\/\/”
  • “:”:平行点,即:

这些只是一些扩大线条样式范围的想法

您可以使用
破折号
kwarg设置自定义破折号样式

从:

设置破折号顺序,破折号的顺序以点为单位。如果seq为空或seq=(无,无),线型将设置为实心

下面是一些基于您的一些建议的示例。显然,有更多的方法可以定制

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

我想添加一些2021年的附加信息。 在MATPLOTVER中。3.3.4破折号选项略有不同。首先循环使用破折号类型,然后添加比率

import matplotlib.pyplot as plt

plt.figure()

# dashed with dash length 10, space length 5
plt.hlines(3, 0, 5, linestyle="--", dashes=(0,(10,5)))

# dashed with dash length 5, space length 10
plt.hlines(6, 0, 5, linestyle="--", dashes=(0,(5,10)))

plt.ylim(0,10)
plt.show()

结果是:

有关更多信息,请查看