- 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 write text in subscript in the axis labels and the legend using Matplotlib?
To write text in subscript in the axis labels and the legend, we can take the following steps −
Create x and y data points using NumPy.
Plot x and y data points with a super subscript texts label.
Use xlabel and ylabel with subscripts in the text.
Use the legend() method to place a legend in the plot.
Adjust the padding between and around subplots.
To display the figure, use the show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 1000) y = np.exp(x) plt.plot(x, y, label=r'$e^x$', c="red", lw=2) plt.xlabel("$X_{axis}$") plt.ylabel("$Y_{axis}$") plt.legend(loc='upper left') plt.show()
Output
- Related Articles
- How to adjust the space between legend markers and labels in Matplotlib?
- How to change the separation between tick labels and axis labels in Matplotlib?
- How to change the text color of font in the legend using Matplotlib?
- How to set the font size of Matplotlib axis Legend?
- Text alignment in a Matplotlib legend
- Increasing the space for X-axis labels in Matplotlib
- How to change ordinal X-axis label to text labels using ggplot2 in R?
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to add subscript with Text using FabricJS?
- How to set the baseline of subscript with Text using FabricJS?
- How to set the size of subscript with Text using FabricJS?
- How do I make sans serif superscript or subscript text in Matplotlib?
- Hide axis values but keep axis tick labels in matplotlib
- How to change the legend fontname in Matplotlib?
- How do you just show the text label in a plot legend in Matplotlib?

Advertisements