

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Displaying horizontal bar graphs using Matplotlib
In this program, we will plot a bar graph using the matplotlib library. The most important Step in solving matplotlib related problems using the matplotlib library is importing the matplotlib library. The syntax is:
import matplotlib.pyplot as plt
Pyplot is a collection of command style functions that make Matplotlib work like MATLAB. We will use the function barh() for plotting the horizontal bar charts
Algorithm
Step 1: Define a list of values. Step 2: Use the barh() function in the matplotlib.pyplot library and define different parameters like height width, etc. Step 3: Label the axes using xlabel() and ylabel(). Step 3: Plot the graph using show().
Example Code
import matplotlib.pyplot as plt data_x = ['Mumbai', 'Delhi', 'Ahmedabad', 'Banglore'] data_y = [40, 35, 29, 32] plt.xlabel("CITY") plt.ylabel("POPULATION") plt.title("BAR PLOT") plt.barh(data_x, data_y, color='red') plt.show()
Output
- Related Questions & Answers
- Displaying bar graphs using Matplotlib
- How to create broken horizontal bar graphs in matplotlib?
- Horizontal stacked bar chart in Matplotlib
- Adding textures to graphs using Matplotlib
- How can bar graphs be visualized using Bokeh?
- How to make a broken horizontal bar plot in Matplotlib?
- How to plot 3D graphs using Python Matplotlib?
- Plotting multiple line graphs using Pandas and Matplotlib
- How to plot bar graphs with same X coordinates side by side in Matplotlib?
- How to make multipartite graphs using networkx and Matplotlib?
- Plot two horizontal bar charts sharing the same Y-axis in Python Matplotlib
- Plot a bar using matplotlib using a dictionary
- How to show node name in Matplotlib graphs using networkx?
- How to create a horizontal bar graph using ggplot2 in R?
- How to create horizontal stacked bar chart using ggvis in R?
Advertisements