- 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 do I change the axis tick font in a Matplotlib plot when rendering using LaTeX?
To change the axis tick font in matplotlib when rendering using LaTeX, we can take the following Steps −
Create x and y data points using numpy.
Using subplot() method, add a subplot to the current figure.
Set x and y ticks with data points x and y using set_xticks and set_yticks methods, respectively.
Plot x and y using plot() method with color=red.
To set bold font weight, we can use LaTeX representation.
To display the figure, use 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.array([1, 2, 3, 4]) y = np.exp(x) ax1 = plt.subplot() ax1.set_xticks(x) ax1.set_yticks(y) ax1.plot(x, y, c="red") ax1.set_xticklabels(["$\bf{one}$", "$\bf{two}$", "$\bf{three}$", "$\bf{four}$"], rotation=45) ax1.set_yticklabels(["$\bf{:.2f}$".format(y[0]), "$\bf{:.2f}$".format(y[1]), "$\bf{:.2f}$".format(y[2]), "$\bf{:.2f}$".format(y[3])], rotation=45) plt.tight_layout() plt.show()
Output
- Related Articles
- How do I write a Latex formula in the legend of a plot using Matplotlib inside a .py file?
- How to change xticks font size in a matplotlib plot?
- How do I change the font size of the scale in Matplotlib plots?
- How do I convert (or scale) axis values and redefine the tick frequency in Matplotlib?
- Show tick labels when sharing an axis in Matplotlib
- How to change the separation between tick labels and axis labels in Matplotlib?
- How do I change the range of the X-axis with datetimes in Matplotlib?
- Bold font weight for LaTeX axes label in Matplotlib
- How to obtain the same font in Matplotlib output as in LaTex output?
- How can I format a float using matplotlib's LaTeX formatter?
- How do I plot only a table in Matplotlib?
- How do I plot Shapely polygons and objects using Matplotlib?
- How do I plot hatched bars using Pandas and Matplotlib?
- How do I change matplotlib's subplot projection of an existing axis?
- How to append a single labeled tick to X-axis using matplotlib?

Advertisements