- 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 display all label values in Matplotlib?
To display all label values, we can use set_xticklabels() and set_yticklabels() methods.
Steps
Create a list of numbers (x) that can be used to tick the axes.
Get the axis using subplot() that helps to add a subplot to the current figure.
Set the ticks on X and Y axes using set_xticks and set_yticks methods respectively and list x (from step 1).
Set tick labels with label lists (["one", "two", "three", "four"]) and rotation of 45 using set_xticklabels() and set_yticklabels().
To add space between axes and tick labels, we can use tick_params() method with pad argument that helps to add space. Argument direction (in) helps to put ticks inside the axes, and axis (both), parameters to be applied on both the axes.
To show the figure, use plt.show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 2, 3, 4] ax1 = plt.subplot() ax1.set_xticks(x) ax1.set_yticks(x) ax1.set_xticklabels(["one", "two", "three", "four"], rotation=45) ax1.set_yticklabels(["one", "two", "three", "four"], rotation=45) ax1.tick_params(axis="both", direction="in", pad=15) plt.show()
Output
- Related Articles
- How to label a patch in matplotlib?
- How to access axis label object in Matplotlib?
- How to label a line in Matplotlib (Python)?
- How to display Matplotlib Y-axis range using absolute values rather than offset values?
- How to display multiple lines of text in Tkinter Label?
- How to concatenate a Python dictionary to display all the values together?
- How to set label for an already plotted line in Matplotlib?
- How to align axis label to the right or top in Matplotlib?
- How to use multiple font sizes in one label in Python Matplotlib?
- How to display pie charts in Matplotlib Python?
- How to improve the label placement for Matplotlib scatter chart?
- How to customize the axis label in a Seaborn jointplot using Matplotlib?
- MongoDB query to display all the values excluding the id?
- Top label for Matplotlib colorbars
- Update all varchar column rows to display values before slash in MySQL?

Advertisements