matplotlib 基础
利用 matplotlib 进行简单绘图
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-np.pi, np.pi, 256, endpoint = True)
C, S = np.cos(x), np.sin(x)
# 设置线条样式
plt.plot(x, C, color = "red", linewidth = 2.5, linestyle = '-')
plt.plot(x, S, color = "blue", linewidth = 2.5, linestyle = '-')
plt.show()
matplotlib.pyplot.plot 函数常用。
# 设置横轴、纵轴的界限
plt.xlim(x.min() * 1.1, x.max() * 1.1)
npi = np.pi
plt.xticks([-npi, -npi / 2, 0, npi / 2, npi], [r'$-\pi$', r'$-\pi/2$', r'$0$', r'$\pi/2$', r'$\pi$']) # 值和标签
plt.ylim(C.min() * 1.1, C.max() * 1.1)
plt.yticks([-1, 0, 1], [r'$-1$', r'$0$', r'$1$'])
标签:plt,npi,1.1,matplotlib,np,pi
From: https://www.cnblogs.com/mklzc/p/18427211