- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plot a bar using matplotlib using a dictionary
First, we can define our dictionary and then, convert that dictionary into keys and values. Finally, we can use the data to plot a bar chart.
Steps
Create a dictionary, i.e., data, where milk and water are the keys.
Get the list of keys of the dictionary.
Get the list of values of the dictionary.
Plot the bar using plt.bar().
Using plt.show(), show the figure.
Example
import matplotlib.pyplot as plt data = {'milk': 60, 'water': 10} names = list(data.keys()) values = list(data.values()) plt.bar(range(len(data)), values, tick_label=names) plt.show()
Output
- Related Articles
- How to add a legend on Seaborn facetgrid bar plot using Matplotlib?
- How to plot a very simple bar chart (Python, Matplotlib) using input *.txt file?
- Dynamically updating a bar plot in Matplotlib
- How to turn off error bars in Seaborn Bar Plot using Matplotlib?
- Displaying bar graphs using Matplotlib
- How to plot a wav file using Matplotlib?
- Plot data from a .txt file using matplotlib
- How to get a Gantt plot using matplotlib?
- Displaying horizontal bar graphs using Matplotlib
- Plot multiple time-series DataFrames into a single plot using Pandas (Matplotlib)
- How to make a broken horizontal bar plot in Matplotlib?
- Plot scatter points using plot method in Matplotlib
- Define the size of a grid on a plot using Matplotlib
- How to plot a rectangle on a datetime axis using Matplotlib?
- How to plot a bar graph in Matplotlib from a Pandas series?

Advertisements