How to set the line width of error bar caps, in matplotlib?

后端 未结 2 753

How can the line width of the error bar caps in Matplotlib be changed?

I tried the following code:

(_, caplines, _) = matplotlib.pyplot.errorbar(
            


        
相关标签:
2条回答
  • 2020-12-30 19:33

    This is based on @joaquin's answer, but a little more concise (if you just want plain error caps with no special styling):

    distance = [1,3,7,9]
    energy = [10,20,30,40]
    sigma = [1,3,2,5]
    
    plt.errorbar(distance, 
        energy, 
        sigma, 
        capsize=5, 
        elinewidth=2,
        markeredgewidth=2)
    

    0 讨论(0)
  • EOL, you were very close..,

    distance = [1,3,7,9]
    energy = [10,20,30,40]
    sigma = [1,3,2,5]
    
    (_, caps, _) = plt.errorbar(distance, energy, sigma, capsize=20, elinewidth=3)
    
    for cap in caps:
        cap.set_color('red')
        cap.set_markeredgewidth(10)
    
    plt.show
    

    enter image description here

    set_markeredgewidth sets the width of the cap lines.

    Matplotlib objects have so many attributes that often it is difficult to remember the right ones for a given object. IPython is a very useful tool for introspecting matplotlib. I used it to analyze the properties of the 2Dlines correponding to the error cap lines and I found that and other marker properties.

    Cheers

    0 讨论(0)
提交回复
热议问题