
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Create a Legend with Pandas and Matplotlib Pyplot
To create a legend with Pandas and matplotib.pyplot(), we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Make a two-dimensional, size-mutable, potentially heterogeneous tabular data.
- Plot the dataframe instance with bar class by name and legend is True.
- To display the figure, use show() method.
Example
import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() df = pd.DataFrame({'Numbers': [3, 4, 1, 7, 8, 5], 'Frequency': [2, 4, 1, 4, 3, 2]}) df.plot(ax=ax, kind='bar', legend=True) plt.show()
Output
Advertisements