- 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 set axis ticks in multiples of pi in Python Matplotlib?
To set axis ticks in multiples of pi in Python, we take following steps −
Initialize a pi variable, create theta and y data points using numpy.
Plot theta and y using plot() method.
Get or set the current tick locations and labels of the X-axis using xticks() method.
Convenience method to set or retrieve autoscaling margins using margins() method.
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 pi = np.pi theta = np.arange(-2 * pi, 2 * pi+pi/2, step=(pi / 2)) y = np.sin(theta) plt.plot(theta, y) plt.xticks(theta, ['-2π', '-3π/2', 'π', '-π/2', '0', 'π/2', 'π', '3π/2', '2π']) plt.margins(x=0) plt.show()
Output
- Related Articles
- How to customize X-axis ticks in Matplotlib?
- How to set the number of ticks in plt.colorbar in Matplotlib?
- How to set X-axis values in Matplotlib Python?
- Adding extra axis ticks using Matplotlib
- How to add third level of ticks in Python Matplotlib?
- How to set the ticks on a Fixed Position in Matplotlib?
- How can I set the location of minor ticks in Matplotlib?
- How to remove the digits after the decimal point in axis ticks in Matplotlib?
- How to turn on minor ticks only on the y-axis Matplotlib?
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?
- How to set "step" on axis X in my figure in Matplotlib Python 2.6.6?
- How to set the unit length of an axis in Matplotlib?
- How to set the value of the axis multiplier in matplotlib?
- Remove the X-axis ticks while keeping the grids (Matplotlib)

Advertisements