- 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
How to plot categorical variables in Matplotlib?
To plot categorical variables in Matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a dictionary with some details.
- Extract the keys and values from the dictionary (Step 2).
- Create a figure and a set of subplots.
- Plot bar, scatter and plot with names and values data.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = {'apple': 10, 'orange': 15, 'lemon': 5} names = list(data.keys()) values = list(data.values()) fig, axs = plt.subplots(1, 3) axs[0].bar(names, values) axs[1].scatter(names, values) axs[2].plot(names, values) plt.show()
Output
- Related Articles
- Plot different colors for different categorical levels using matplotlib
- How to visualize two categorical variables together in R?
- How to detect multicollinearity in categorical variables using R?
- How to a plot stem plot in Matplotlib Python?
- How to plot matplotlib contour?
- How to plot blurred points in Matplotlib?
- How to plot overlapping lines in Matplotlib?
- How to plot hexbin histogram in Matplotlib?
- How to plot multiple graphs in Matplotlib?
- How to plot a circle in Matplotlib?
- How to plot signal in Matplotlib in Python?
- How to plot cdf in Matplotlib in Python?
- Correlation Between Categorical and Continuous Variables
- How to remove lines in a Matplotlib plot?
- How to animate a scatter plot in Matplotlib?

Advertisements