The document explains how to create bar plots using the Matplotlib library in Python, detailing the bar() function and its parameters. It describes both simple and stacked bar plots, illustrating how to represent categorical data visually. Additionally, it provides examples of labeling axes and customizing bar colors.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
20 views
Bar Graph Using Matplotlib
The document explains how to create bar plots using the Matplotlib library in Python, detailing the bar() function and its parameters. It describes both simple and stacked bar plots, illustrating how to represent categorical data visually. Additionally, it provides examples of labeling axes and customizing bar colors.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 7
BAR GRAPH
USING MATPLOTLIB BAR PLOT IN MATPLOTLIB
• A bar plot or bar chart is a graph that
represents the category of data with rectangular bars with lengths and heights that is proportional to the values which they represent. • The bar plots can be plotted horizontally or vertically. CREATING A BAR PLOT • The matplotlib API in Python provides the bar() function which can be used in MATLAB style use or as an object-oriented API. • The syntax of the bar() function to be used with the axes is as follows:- plt.bar(x, height, width, bottom, align)
The function creates a bar plot bounded with a
rectangle depending on the given parameters. Following is a simple example of the bar plot, which represents the number of students enrolled in different courses of an institute. EXAMPLEPROGRAM Output : • Here plt.bar(courses, values, color=’maroon’) is used to specify that the bar chart is to be plotted by using the courses column as the X- axis, and the values as the Y-axis. • The color attribute is used to set the color of the bars(maroon in this case).plt.xlabel(“Courses offered”) and plt.ylabel(“students enrolled”) are used to label the corresponding axes.plt.title() is used to make a title for the graph.plt.show() is used to show the graph as output using the previous commands. MULTIPLE BAR PLOTS • Multiple bar plots are used when comparison among the data set is to be done when one variable is changing. We can easily convert it as a stacked area bar chart, where each subgroup is displayed by one on top of the others. It can be plotted by varying the thickness and position of the bars. Following bar plot shows the number of students passed in the engineering branch: STACKED BAR PLOT • Stacked bar plots represent different groups on top of one another. • height of the bar depends on the resulting height of the combination of the results of the groups. • It goes from the bottom to the value instead of going from zero to value. The following bar plot represents the contribution of boys and girls in the team.