共画出四个图,程序如下所示
import matplotlib.pyplot as plt
import numpy as np
p1 = plt.figure(figsize=(8,8),dpi=80) # # 画布大小,分辨率
# 修改参数
plt.rcParams['font.sans-serif'] = 'SimHei' # 仿宋
plt.rcParams['axes.unicode_minus'] = False # 设置正常显示符号
p1.add_subplot(2,2,1)
# 画圆
r = 1
a = np.arange(0,2*np.pi,0.01) # 步长越小图线越平滑
x = r*np.cos(a)
y = r*np.sin(a)
plt.plot(x,y,color='red')
plt.title('子图1')
plt.legend(['圆'])
p1.add_subplot(2,2,2)
# 画正弦曲线
x = np.arange(-2*np.pi,2*np.pi,0.001)
y = np.sin(x)
plt.plot(x,y,color='blue')
plt.title('子图2')
plt.legend(['正弦'])
p1.add_subplot(2,2,3)
# 余弦
x = np.arange(-2*np.pi,2*np.pi,0.