"""
matplotlib的基本使用
"""
import matplotlib.pyplot as mp
import numpy as np
x = np.linspace(0, 2 * np.pi, 1000)
y_sin = np.sin(x)
y_cos = np.cos(x)
mp.plot(x, y_sin, linestyle=":", linewidth=2, color=(0, 0, 0.8, 1.0), label="y=sin(x)")
mp.plot(x, y_cos, linestyle="-.", linewidth=3, color="r", label="y=cos(x)")
mp.xlim(0, 2 * np.pi)
mp.ylim(-1.2, 1.2)
mp.xticks([0, np.pi / 2, np.pi, 3 * np.pi / 2, 2 * np.pi],
["0", r"$\frac{\pi}{2}$", r"$\pi$", r"$\frac{3\pi}{2}$", r"$2\pi$"])
ax = mp.gca()
ax.spines["top"].set_color("none")
ax.spines["right"].set_color("none")
ax.spines["bottom"].set_position(("data", 0))
pointX = [np.pi, np.pi]
pointy = [-1, 0]
mp.scatter(pointX, pointy, marker='o', s=70, label="sample point", zorder=3)
mp.legend()
mp.annotate(
r'$\pi$',
xycoords='data',
xy=(np.pi, -1),
textcoords='offset points',
xytext=(20, -30),
fontsize=14,
arrowprops=dict(
arrowstyle='-|>',
connectionstyle='angle3'
))
mp.show()