- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 can I change the font size of ticks of axes object in Matplotlib?
To change the font size of ticks of axes object in matplotlib, we can take the following steps −
Create x and y data points using numpy.
Using subplots() method, create a figure and a set of subplots (fig and ax).
Plot x and y data points using plot() method, with color=red and linewidth=5.
Set xticks with x data points.
Get the list of major ticks using get_major_ticks() method.
Iterate the major ticks (from step 5), and set the font size and rotate them by 45 degrees.
To display the figure, use show() method.
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 = np.sin(x) fig, ax = plt.subplots() ax.plot(x, y, c='red', lw=5) ax.set_xticks(x) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(14) tick.label.set_rotation('45') plt.tight_layout() plt.show()
Output
- Related Articles
- How do I change the font size of ticks of matplotlib.pyplot.colorbar.ColorbarBase?
- How do I change the font size of the scale in Matplotlib plots?
- How can I change the font family and font size with jQuery?
- How to change the font size of scientific notation in Matplotlib?
- How can I set the location of minor ticks in Matplotlib?
- How to change xticks font size in a matplotlib plot?
- How can I hide the axes in Matplotlib 3D?
- How to change the font size of textView in android?
- How to change the color of the ticks in the colorbar in Matplotlib?
- How to change the spacing between ticks in Matplotlib?
- Can I change the size of UIActivityIndicator in Swift?
- How to set the font size of Matplotlib axis Legend?
- How to change the font size of Text using FabricJS?
- How to change font size in HTML?
- How to change font size in ttk.Button?

Advertisements