- 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 access axis label object in Matplotlib?
To axes axis label object in Matplotlib, we can use ax.xaxis.get_label().get_text() method.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create a figure and a set of subplots.
- Initialize a variable, N, for number samples.
- Create random data points using numpy.
- Plot x data points using plot() method.
- Set X-axis label using set_xlabel() method.
- To get the xlabel, use get_label() method and get_text() method.
- To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() N = 100 x = np.random.rand(N) ax.plot(x) ax.set_xlabel("X-axis") x_lab = ax.xaxis.get_label() print("Label is: ", x_lab.get_text()) plt.show()
Output
- Related Articles
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib
- How to align axis label to the right or top in Matplotlib?
- How to customize the axis label in a Seaborn jointplot using Matplotlib?
- How to print the Y-axis label horizontally in a Matplotlib/Pylab chart?
- How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?
- How to label a patch in matplotlib?
- Changing the color of a single X-axis tick label in Matplotlib
- How to add axis label to chart in Excel?
- How to label a line in Matplotlib (Python)?
- How to display all label values in Matplotlib?
- How to enforce axis range in Matplotlib?
- How to customize the X-axis in Matplotlib?
- How to customize X-axis ticks in Matplotlib?
- How to remove relative shift in Matplotlib axis?
- How to access an object through another object in JavaScript?

Advertisements