Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Pylab scatter plot error bars (the error on each point is unique)

I am attempting a scatter plot of 2 arrays for which I have a third array containing the absolute error (error in y direction) on each point. I want the error bars to between (point a - error on a) and (point a + error on a). Is there a way of achieving this with pylab and if not any ideas on how else I could do it?

like image 676
user3412782 Avatar asked Mar 12 '14 21:03

user3412782


People also ask

How do you plot multiple error bars in Python?

By using the plt. errorbar() method we plot the error bars and pass the argument xerr to plot error on the x values in the scatter plot. In the above example, we import matplotlib. pyplot library and define the data point on the x-axis and y-axis.

How does Python calculate error bars?

Error bars in line plotserrorbar() method is used to create a line plot with error bars. The two positional arguments supplied to ax. errorbar() are the lists or arrays of x, y data points. The two keyword arguments xerr= and yerr= define the error bar lengths in the x and y directions.


1 Answers

This is almost like the other answer but you don't need a scatter plot at all, you can simply specify a scatter-plot-like format (fmt-parameter) for errorbar:

import matplotlib.pyplot as plt x = [1, 2, 3, 4] y = [1, 4, 9, 16] e = [0.5, 1., 1.5, 2.] plt.errorbar(x, y, yerr=e, fmt='o') plt.show() 

Result:

enter image description here

A list of the avaiable fmt parameters can be found for example in the plot documentation:

character   description '-'     solid line style '--'    dashed line style '-.'    dash-dot line style ':'     dotted line style '.'     point marker ','     pixel marker 'o'     circle marker 'v'     triangle_down marker '^'     triangle_up marker '<'     triangle_left marker '>'     triangle_right marker '1'     tri_down marker '2'     tri_up marker '3'     tri_left marker '4'     tri_right marker 's'     square marker 'p'     pentagon marker '*'     star marker 'h'     hexagon1 marker 'H'     hexagon2 marker '+'     plus marker 'x'     x marker 'D'     diamond marker 'd'     thin_diamond marker '|'     vline marker '_'     hline marker 
like image 69
MSeifert Avatar answered Oct 03 '22 05:10

MSeifert