python pyplot 生成具有不同破折号参数的线型循环
python pyplot produce linestyle cycles with different dashes parameters
我正在写 class 是为了制作符合我多种需求的情节人物!
特别是我专注于每个 pyplot 用户都知道有 4 种线型('-'、'--'、'-.'、':')的线型的循环(颜色和线型)
但是有一个选项 .. "dashes=L,ES" (Line, Empty space) 目的是创建具有不同 spaces 的行来跟踪...我如何在 linestyle 中管理它环形 ??
嗯,我知道元组的语法...但是我必须在哪里使用它?
这是我目前定义的样式
def linestyles(self, style : str = 'ls1'):
linestyle = {}
linestyle['ls1'] = ['-', '--', ':', '-.','-','--',':','-.']
linestyle['ls10'] = ['-', '--', ':', '-.','-','--',':','-.','-','--']
linestyle['llt8'] = ['-','--','-','--','-','--','-','--']
linestyle['lp8'] = ['-',':','-',':','-',':','-',':']
linestyle['llt10'] = ['-','--','-','--','-','--','-','--','-','--']
linestyle['lp10'] = ['-',':','-',':','-',':','-',':','-',':']
return linestyle[style]
我必须在哪里指定破折号??
编辑 问题是我不知道如何循环进入它们的正确方法:
linestyle['ldash'] = ['(0, ()))','(0, (1, 10)))','(0, (1, 5)))','(0, (1, 1)))']
如果我将其插入我的列表中,则不起作用
编辑 抱歉,您在回答开头告诉我不能是字符串!!我解决了!!考虑这个 post 关闭!非常感谢
元组不是字符串,它们应该是 python 元组。 IE。使用 (0, (1, 5))
而不是 '(0, (1, 5)))'
.
通常,指定线型的一种方法是通过 linestyle
参数。你可以遍历一个列表,
import matplotlib.pyplot as plt
linestyles = ["--", (0,(5,2,5,5,1,4))]
for i,ls in enumerate(linestyles):
plt.plot([0,1],[i,i], linestyle=ls)
plt.show()
或创建线型循环器,
import matplotlib.pyplot as plt
linestyles = ["--", (0,(5,2,5,5,1,4))]
plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", linestyles)
for i in range(2):
plt.plot([0,1],[i,i])
plt.show()
在这两种情况下,结果图都将如下所示
另请参阅linestyles example。
我正在写 class 是为了制作符合我多种需求的情节人物! 特别是我专注于每个 pyplot 用户都知道有 4 种线型('-'、'--'、'-.'、':')的线型的循环(颜色和线型) 但是有一个选项 .. "dashes=L,ES" (Line, Empty space) 目的是创建具有不同 spaces 的行来跟踪...我如何在 linestyle 中管理它环形 ??
嗯,我知道元组的语法...但是我必须在哪里使用它?
这是我目前定义的样式
def linestyles(self, style : str = 'ls1'):
linestyle = {}
linestyle['ls1'] = ['-', '--', ':', '-.','-','--',':','-.']
linestyle['ls10'] = ['-', '--', ':', '-.','-','--',':','-.','-','--']
linestyle['llt8'] = ['-','--','-','--','-','--','-','--']
linestyle['lp8'] = ['-',':','-',':','-',':','-',':']
linestyle['llt10'] = ['-','--','-','--','-','--','-','--','-','--']
linestyle['lp10'] = ['-',':','-',':','-',':','-',':','-',':']
return linestyle[style]
我必须在哪里指定破折号??
编辑 问题是我不知道如何循环进入它们的正确方法:
linestyle['ldash'] = ['(0, ()))','(0, (1, 10)))','(0, (1, 5)))','(0, (1, 1)))']
如果我将其插入我的列表中,则不起作用
编辑 抱歉,您在回答开头告诉我不能是字符串!!我解决了!!考虑这个 post 关闭!非常感谢
元组不是字符串,它们应该是 python 元组。 IE。使用 (0, (1, 5))
而不是 '(0, (1, 5)))'
.
通常,指定线型的一种方法是通过 linestyle
参数。你可以遍历一个列表,
import matplotlib.pyplot as plt
linestyles = ["--", (0,(5,2,5,5,1,4))]
for i,ls in enumerate(linestyles):
plt.plot([0,1],[i,i], linestyle=ls)
plt.show()
或创建线型循环器,
import matplotlib.pyplot as plt
linestyles = ["--", (0,(5,2,5,5,1,4))]
plt.rcParams["axes.prop_cycle"] += plt.cycler("linestyle", linestyles)
for i in range(2):
plt.plot([0,1],[i,i])
plt.show()
在这两种情况下,结果图都将如下所示
另请参阅linestyles example。