【问题标题】:Matplotlib: how to set dashes in a dictionary?Matplotlib:如何在字典中设置破折号?
【发布时间】:2012-05-04 13:05:57
【问题描述】:

谁能告诉我如何在字典中使用自定义破折号序列。我无法让它运行,我唯一不能使用的东西(不是程序员)是文档 =-(

def lineCycler(): #must be invoked for every plot again to get the same results in every plot
    #hasy="#7b9aae"
    _styles = [{'color':'#b21a6a', 'ls':'-'},
               {'color':'#65a4cb', 'ls':'[5,2,10,5]'},# this shoul be some custom dash sequnece
               {'color':'#22b27c', 'ls':'-.'},
               {'color':'k', 'ls':'--'}
            ]

    _linecycler=cycle(_styles)
    return _linecycler

【问题讨论】:

    标签: matplotlib


    【解决方案1】:

    为此使用 dashes 关键字(您需要一个列表,而不是字符串):

    def lineCycler(): 
        _styles = [{'color':'#b21a6a', 'ls':'-'},
                   {'color':'#65a4cb', 'dashes':[5,2,10,5]},
                   {'color':'#22b27c', 'ls':'-.'},
                   {'color':'k', 'ls':'--'}
                ]
    
        _linecycler=cycle(_styles)
        return _linecycler
    

    【讨论】:

    • 非常感谢。我测试了(感觉像)百万个设置,但错过了。
    猜你喜欢
    • 2015-09-19
    • 2023-02-08
    • 1970-01-01
    • 2011-12-17
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多