- 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 a Pandas multi-index dataFrame with all xticks (Matplotlib)?
To plot a Pandas multi-index data frame with all xticks, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create index value with 1000 smaples data.
- Make a one-dimensional ndarray with axis labels.
- Get the mean value of the series.
- Plot g dataframe.
- Set the ticks and ticklabel on the current axes
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True idx = pd.date_range("2020-01-01", periods=1000) val = np.random.rand(1000) s = pd.Series(val, idx) g = s.groupby([s.index.year, s.index.month]).mean() ax = g.plot() ax.set_xticks(range(len(g))) ax.set_xticklabels(["%s-%02d" % item for item in g.index.tolist()], rotation=45, ha='center') plt.show()
Output
- Related Articles
- How to plot a Pandas Dataframe with Matplotlib?
- How to plot a time as an index value in a Pandas dataframe in Matplotlib?
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Plot a Line Graph for Pandas Dataframe with Matplotlib?
- Matplotlib – How to set xticks and yticks with imshow plot?
- Python - Plot a Pie Chart for Pandas Dataframe with Matplotlib?
- How to change xticks font size in a matplotlib plot?
- How to plot certain rows of a Pandas dataframe using Matplotlib?
- How to plot an area in a Pandas dataframe in Matplotlib Python?
- How to change the DPI of a Pandas Dataframe Plot in Matplotlib?
- Annotating points from a Pandas Dataframe in Matplotlib plot
- Frequency plot in Python/Pandas DataFrame using Matplotlib
- Python Pandas - Display the index of dataframe in the form of multi-index
- How to make a multi-index in Pandas?
- Python – Drop a level from a multi-level column index in Pandas dataframe

Advertisements