Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I tried the following code:

(_, caplines, _) = matplotlib.pyplot.errorbar(     data['distance'], data['energy'], yerr=data['energy sigma'],     capsize=10, elinewidth=3)  for capline in caplines:     capline.set_linewidth(10)     capline.set_color('red')  pp.draw() 

Unfortunately, this updates the color of the caps, but does not update the line width of the caps!

The resulting effect is similar to the "fat error bar lines / thin caps" in the following image: enter image description here

It would be nice to have "fat" bar caps, in the case; how can this be done, in Matplotlib? Drawing the bar caps "manually", one by one with plot() would work, but a simpler alternative would be best.

like image 590
Eric O Lebigot Avatar asked Sep 29 '11 17:09

Eric O Lebigot


People also ask

How do I change the width of a line in Matplotlib?

matplotlib.pyplot.plot(x, y, linewidth=1.5) By default, the line width is 1.5 but you can adjust this to any value greater than 0.

How do you increase the size of error bars?

You can make the error bar thicker by setting the elinewidth attribute in the call to errorbar(x,y,...) errorbar documentation. But the length of the error bar is your data: you can't change the length without changing the error that it represents.

How do I change the thickness of a line in Pyplot?

Matplotlib allows you to adjust the line width of a graph plot using the linewidth attribute. If you want to make the line width of a graph plot thinner, then you can make linewidth less than 1, such as 0.5 or 0.25.

Which of the following parameter is used to set the color of a error bar in bar plots?

ecolor: This parameter is an optional parameter. And it is the color of the errorbar lines with default value NONE. elinewidth: This parameter is also an optional parameter.


1 Answers

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

like image 142
joaquin Avatar answered Sep 22 '22 20:09

joaquin