import matplotlib.pyplot as plt from matplotlib.ticker import FixedLocator, FuncFormatter import numpy as np X1 = np.arange(0, 8*np.pi, 0.01) Y1 = np.cos(X1) plt.plot(X1, Y1) X2 = np.array([i*np.pi for i in range(9)]) X3 = np.array([i*np.pi/2 for i in range(1, 16, 2)]) Y2 = np.cos(X2) Y3 = np.cos(X3) plt.scatter(X2, Y2, color="green") plt.scatter(X3, Y3, color="red") plt.gca().xaxis.set_major_locator(FixedLocator(X2)) plt.gca().xaxis.set_major_formatter(FuncFormatter(lambda x,_: "${}\\pi$".format(x // np.pi))) plt.show()