
- 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
How to make a mosaic plot in Matplotlib?
To make a mosaic plot in matplotlib, we can take the following steps.
Steps
Set the figure size and adjust the padding between and around the subplots.
Install statsmodel package (pip install statsmodels). It is required to create mosaic plots. statsmodels is a Python package that provides a complement to scipy for statistical computations including descriptive statistics and estimation and inference for statistical models.
Make a dictionary for mosaic plot.
Create a mosaic plot from a contingency table.
To display the figure, use Show() method.
Example
import matplotlib.pyplot as plt from statsmodels.graphics.mosaicplot import mosaic plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Dictionary for mosaic plot data = {'John': 7, 'Joe': 10, 'James': 5, 'Kate': 1} # Create mosaic plot mosaic(data, title='Basic mosaic plot') # Display the figure plt.show()
Output
It will produce the following output −
- Related Questions & Answers
- How to make a rug plot in Matplotlib?
- How to make a simple lollipop plot in Matplotlib?
- How to make a broken horizontal bar plot in Matplotlib?
- How to make a quiver plot in polar coordinates using Matplotlib?
- How to make a discrete colorbar for a scatter plot in matplotlib?
- How to make a 4D plot with Matplotlib using arbitrary data?
- Make a multiline plot from .CSV file in matplotlib
- How to a plot stem plot in Matplotlib Python?
- How can I make a scatter plot colored by density in Matplotlib?
- How to plot a circle in Matplotlib?
- How to surface plot/3D plot from a dataframe (Matplotlib)?
- How to remove lines in a Matplotlib plot?
- How to animate a scatter plot in Matplotlib?
- How to animate a line plot in Matplotlib?
- How to plot a 2D histogram in Matplotlib?
Advertisements