gpt4 book ai didi

python pyplot 产生具有不同虚线参数的线型循环

转载 作者:行者123 更新时间:2023-12-01 09:14:41 25 4
gpt4 key购买 nike

我正在编写一门类(class),以便制作符合我的多种需求的情节人物!我特别关注每个 pyplot 用户都知道的线型的循环(颜色和线型),有 4 种线型('-'、'--'、'-.'、':')但有一个选项..“破折号=L,ES”(线条,空白空间),其目的是创建具有不同空间的线条来跟踪...我如何在线条样式循环中管理它?

我知道元组的语法...但是我必须在哪里使用它?

这是我到目前为止定义的样式

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

如果我将其插入列表中,则不起作用

编辑抱歉,您在答案开始时告诉我不能是字符串!我解决了!!考虑这篇文章关闭!非常感谢

最佳答案

元组并不意味着是字符串,它们应该是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()

在这两种情况下,结果图将如下所示

enter image description here

另请参阅 linestyles example .

关于python pyplot 产生具有不同虚线参数的线型循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51363815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com