Python | Error Bar in Bar Graph

Python | Error Bar in Bar Graph: Here, we will learn about the Error Bar in Bar Graph and its Python implementation.
Submitted by Anuj Singh, on July 14, 2020

Error is a mathematical term often used to express the extent of quantity (as a probability). In matplotlib, there is a command for visualizing error in bar graphs xerror and yerror.

In this article, we are going to show the use and implementation of error bars in horizontal and vertical bar graphs.

Furthermore, we have a freehand command for changing the colors of error bars.

Syntax:

matplotlib.bar(people, performance, yerr=error, ecolor='r')
Python | Error Bar in Bar Graph (1)

Python | Error Bar in Bar Graph (2)

Python | Error Bar in Bar Graph (3)

Reference: https://matplotlib.org/

Python code for error bar in bar graph

import matplotlib.pyplot as plt
import numpy as np

# Example data
people = ['Tom', 'Dick', 'Harry', 'Slim', 'Jim']
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

# Default Error Bar 
plt.figure()
plt.bar(people, performance, yerr=error)
plt.ylabel('Performance')
plt.title('How fast do you want to go today?')
plt.show()

# Default Error Bar 
plt.figure()
plt.barh(people, performance, xerr=error, align='center')
plt.xlabel('Performance')
plt.title('How fast do you want to go today?')
plt.show()

# Red Error Bar
plt.figure()
plt.barh(people, performance, xerr=error, ecolor='r')
plt.xlabel('Performance')
plt.title('How fast do you want to go today?')
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.