Error bars function used as graphical enhancement that visualizes the variability of the plotted data on a Cartesian graph. Error bars can be applied to graphs to provide an additional layer of detail on the presented data. As you can see in below graphs.


Error bars help you indicate estimated error or uncertainty to give a general sense of how precise a measurement is this is done through the use of markers drawn over the original graph and its data points. To visualize this information error bars work by drawing lines that extend from the center of the plotted data point or edge with bar charts the length of an error bar helps to reveal uncertainty of a data point as shown in the below graph. A short error bar shows that values are concentrated signaling that the plotted averaged value is more likely while a long error bar would indicate that the values are more spread out and less reliable. also depending on the type of data. the length of each pair of error bars tends to be of equal length on both sides, however, if the data is skewed then the lengths on each side would be unbalanced.

Error bars always run parallel to a quantity of scale axis so they can be displayed either vertically or horizontally depending on whether the quantitative scale is on the y-axis or x-axis if there are two quantity of scales and two pairs of arrow bars can be used for both axes.

Let see an example of errorbar how it works.
Creating a Simple Graph.
Python3
import matplotlib.pyplot as plt
x =[1, 2, 3, 4, 5, 6, 7]
y =[1, 2, 1, 2, 1, 2, 1]
plt.plot(x, y)
|
Output:

Example 1: Adding Some error in y value.
Python3
import matplotlib.pyplot as plt
x =[1, 2, 3, 4, 5, 6, 7]
y =[1, 2, 1, 2, 1, 2, 1]
y_error = 0.2
plt.plot(x, y)
plt.errorbar(x, y,
yerr = y_error,
fmt ='o')
|
Output:

Example 2: Adding Some error in x value.
Python3
import matplotlib.pyplot as plt
x =[1, 2, 3, 4, 5, 6, 7]
y =[1, 2, 1, 2, 1, 2, 1]
x_error = 0.5
plt.plot(x, y)
plt.errorbar(x, y,
xerr = x_error,
fmt ='o')
|
Output:

Example 3: Adding error in x & y
Python3
import matplotlib.pyplot as plt
x =[1, 2, 3, 4, 5, 6, 7]
y =[1, 2, 1, 2, 1, 2, 1]
x_error = 0.5
y_error = 0.3
plt.plot(x, y)
plt.errorbar(x, y,
yerr = y_error,
xerr = x_error,
fmt ='o')
|
Output:

Example 4: Adding variable error in x and y
Python3
import matplotlib.pyplot as plt
x =[1, 2, 3, 4, 5]
y =[1, 2, 1, 2, 1]
y_errormin =[0.1, 0.5, 0.9,
0.1, 0.9]
y_errormax =[0.2, 0.4, 0.6,
0.4, 0.2]
x_error = 0.5
y_error =[y_errormin, y_errormax]
plt.errorbar(x, y,
yerr = y_error,
xerr = x_error,
fmt ='o')
|
Output:

Example 5:
Python3
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10)/10
y = (x + 0.1)**2
y_error = np.linspace(0.05, 0.2, 10)
plt.plot(x, y)
plt.errorbar(x, y, yerr = y_error, fmt ='o')
|
Output:

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Last Updated :
14 Jan, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...