1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axisartist.axislines import AxesZero
fig = plt.figure() ax = fig.add_subplot(axes_class=AxesZero)
ax.set_xlabel('x') ax.set_ylabel('y')
ax.grid(True, color='#b0b0b0')
for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>")
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False)
x = np.linspace(-2 * np.pi, 2 * np.pi, 80) y = np.sin(x)
ax.plot(x, y, linestyle='--', color='red', marker='*')
ax.set_xticks(np.linspace(-2 * np.pi, 2 * np.pi, 5), ["$-2\pi$", "$-\pi$", "$0$", "$\pi$", "$2\pi$"])
plt.show()
|