scientific-programming-exer.../ex_23.py

24 lines
535 B
Python
Raw Normal View History

2018-11-28 16:10:29 +00:00
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()