![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 do I make sans serif superscript or subscript text in Matplotlib?
To make superscript or subscript text in matplotlib, use LaTeX representation.
Steps
Create x and y data points using numpy.
Plot x and y data point using plot() method.
Put the title with LateX representation using title() method.
Use xlabel and ylabel methods to set the label of the axes.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 10) y = 2**x plt.plot(x, y) plt.title('$Y=2^{X}$') plt.xlabel('$X_{data}$') plt.ylabel('$Y_{data}$') plt.show()
Output
Advertisements