
- 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 add legends and title to grouped histograms generated by Pandas? (Matplotlib)
To add legends and title to grouped histograms generated by Pandas, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a Pandas dataframe with "a", "b", "c" and "d" keys.
- Plot data frame with kind="hist"
- Set a title for the axes.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'a': [1, 1, 1, 1, 3], 'b': [1, 1, 2, 1, 3], 'c': [2, 2, 2, 1, 3], 'd': [2, 1, 2, 1, 3], }) df.plot(kind='hist') plt.title("Grouped Histograms") plt.show()
Output
- Related Questions & Answers
- How to plot histograms from dataframes in Pandas using Matplotlib?
- How to plot two histograms side by side using Matplotlib?
- Plotting histograms against classes in Pandas / Matplotlib
- How to Add Legends to charts in Python?
- Matplotlib legends in subplot
- How to plot two Pandas time series on the same plot with legends and secondary Y-axis in Matplotlib?
- Python – Sort grouped Pandas dataframe by group size?
- How can matplotlib be used to create histograms using Python?
- How to make a grouped boxplot graph in matplotlib?
- How to ORDER BY grouped fields in MySQL?
- How to get pixel coordinates for Matplotlib-generated scatterplot?
- How to get all the legends from a plot in Matplotlib?
- How to add a title on Seaborn lmplot?
- Plotting profile histograms in Python Matplotlib
- How to create side by side histograms in base R?
Advertisements