- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)
To add a shared x-label and shared y-label, we can use plot() method with kind="bar", sharex=True and sharey=True.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create a two-dimensional, size-mutable, potentially heterogeneous tabular data.
- Plot the dataframe with kind="bar", sharex=True and sharey=True.
- To display the figure, use show() method.
Example
import pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame( {'First': [0.3, 0.2, 0.5, 0.2], 'Second': [0.1, 0.0, 0.3, 0.1], 'Third': [0.2, 0.5, 0.0, 0.7], 'Fourth': [0.6, 0.3, 0.4, 0.6]}, index=list('1234')) axes = df.plot(kind="bar", subplots=True, layout=(2, 2), sharey=True, sharex=True) plt.show()
Output
- Related Articles
- How to add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)
- How to add a mathematical expression in axis label in a plot created by using plot function in R?
- How to label bubble chart/scatter plot with column from Pandas dataframe?
- How to plot an emoji as a label for a bar in Matplotlib?
- How to give Matplolib imshow plot colorbars a label?
- How to plot a Pandas Dataframe with Matplotlib?
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib
- How to plot a smooth 2D color plot for z = f(x, y) in Matplotlib?
- How do you just show the text label in a plot legend in Matplotlib?
- How to plot two Pandas time series on the same plot with legends and secondary Y-axis in Matplotlib?
- How to convert the X-axis label in a bar plot to italic using ggplot2 in R?
- How to label a patch in matplotlib?
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- How to add text inside a plot in Matplotlib?
- How to plot a Pandas multi-index dataFrame with all xticks (Matplotlib)?
- How to label a line in Matplotlib (Python)?

Advertisements