2

I've been attempting to get the errorbar caps on the bar tips, but yet invoking capsize argument doesn't seem to be working. If you could please take a look at my code below. Many thanks in advance.

Figure1 = plt.figure('Bar Graph', figsize=(7.5,7), dpi=300)
Subplot1 = Figure1.add_subplot(1,1,1)

Subplot1.bar([4,5,6,7], [6,5,9,8], yerr=[0.2,0.3,0.1,0.2],
            width= 0.8, color='r', edgecolor='r', 
            capsize=3, ecolor='black'
             )
Riccardo
  • 115
  • 11
  • Is the bar plot displaying correctly otherwise? Can you upload a picture? – PeptideWitch Aug 08 '19 at 00:54
  • http://tinypic.com/view.php?pic=2h5s2nt&s=9#.XUuAbxRS8UE please have a look at my current plot – Riccardo Aug 08 '19 at 01:53
  • Could you try adding `markeredgewidth=10` to the `bar`? – PeptideWitch Aug 08 '19 at 01:56
  • Well, I did that already as well, however, that seems to be an argument for errorbar() method not bar() function that I'm currently using. Yet< I did it as well just now be be sure, and here is the error AttributeError: Unknown property markeredgewidth – Riccardo Aug 08 '19 at 02:01
  • Using your original code, the error bars show their caps on my outputs. Perhaps add: `matplotlib.rcParams.update({'errorbar.capsize': 2})` before you make the plot? – PeptideWitch Aug 08 '19 at 02:12
  • Alternatively, pass the `markeredgewidth` as a error_kw in the bar plot: `error_kw={'markeredgewidth':10}` – PeptideWitch Aug 08 '19 at 02:13

1 Answers1

2

Seems like this problem has been noted before; sometimes, the error bar width for the caps defaults to zero. So an easy solution is to add markeredgewidth=10 to your barplot call and the caps on the ends of the error bars should return.

Subplot1.bar([4,5,6,7], [6,5,9,8], yerr=[0.2,0.3,0.1,0.2],
            width= 0.8, color='r', edgecolor='r', 
            capsize=3, ecolor='black', error_kw={'markeredgewidth':10},
             )

If this doesn't work, get rid of the error_kw and, before you create the figure, specify matplotlib.rcParams.update({'errorbar.capsize': 2}). You can also then remove the capsize argument from the bar

PeptideWitch
  • 2,239
  • 14
  • 30
  • 1
    Thanks a million. Adding `error_kw={'markeredgewidth':10}` works just fine. Though including `matplotlib.rcParams.update({'errorbar.capsize': 2})` before creating figure did not alter anything. – Riccardo Aug 08 '19 at 03:11