Matplotlib Errorbar Caps Missing

后端 未结 3 1789
你的背包
你的背包 2020-12-01 15:54

I\'m attempting to create a scatter plot with errorbars in matplotlib. The following is an example of what my code looks like:

import matplotlib.pyplot as pl         


        
相关标签:
3条回答
  • 2020-12-01 16:28

    What worked for me was adding this (as per: How to set the line width of error bar caps, in matplotlib):

    (_, caps, _) = plt.errorbar(x,y, yerr=err, capsize=20, elinewidth=3)
    
    for cap in caps:
        cap.set_color('red')
        cap.set_markeredgewidth(10)
    
    0 讨论(0)
  • 2020-12-01 16:29

    Slight simplification of astromax's answer:

    plt.errorbar(x,y, yerr=err, capsize=20, elinewidth=3, markeredgewidth=10)
    

    It seems that somehow markeredgewidth is defaulting to 0 sometimes.

    0 讨论(0)
  • 2020-12-01 16:49

    It has to do with the rcParams in matplotlib. To solve it, add the following lines at the beginning of your script:

    import matplotlib
    matplotlib.rcParams.update({'errorbar.capsize': 2})
    

    It also works with plt.bar().

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