首页 > 解决方案 > 包含绘图设置的 matplotlib 字典

问题描述

我正在开发一个类以生成适合我的 pourpose 的情节......我第一次定义*args要以简单的方式传递给类 =

attribute = [*args]
for in in range(len(attribute)):
   plot(attribute[i],attribute[i+1], attribute[i+3])

哪里args是包含 vector1, vector2, label='for the legend' 的列表

现在我意识到有时我需要传递给我的类 stype 的 plot 方法,更多的参数然后只是一个标签 .. 例如标记,特定的颜色......线宽,所以我认为作为三分之二传递 - th 参数以这种方式解包的字典:

for i in range(0,len(self.variable)-1,3):
            plt.plot(self.variable[i],self.variable[i+1],self.variable[i+2])

但我真的不知道如何通过这本字典..我尝试:

fig1.plot(fet,feu[:,0],{ 'label' : 'Explicit Euler', 'linetype' :'-'},bet,beu[:,0],'Implicit Euler', {}, cnt,cnu[:,0], { 'label' : 'Crank-Nicholson'} )

编辑谢谢大家,但我解决了:

 for i in range(0,len(self.variable)-1,3):
            plt.plot(self.variable[i],self.variable[i+1],**self.variable[i+2], linewidth=3)

标签: python

解决方案


推荐阅读