plot画线形图(子图)
import numpyas np
import matplotlib.pyplotas plt
N =25
np.random.seed(100)
x = np.linspace(0., 10., N)
y = np.sin(x) **2 + np.cos(x)
plt.figure(figsize=(15, 10))
rows =2
columns =2
# 定义网格子图数量 两行、两列、间隔0.25
grid = plt.GridSpec(rows, columns, wspace=.25, hspace=.25)
# 定义线图线的样式
linesstyles = ['-', '--', '-.', ':']
# 线上的标记点
mark = [2, 5, 10, 12]
# 不同线的颜色定义
color = ['#00429d', '#627c94', '#f4777f', '#93003a']
for i in range(len(linesstyles)):
plt.subplot(grid[i])
plt.plot(x, y, 'o', label=r'$y = sin(x)^2+ cos(x)$', linestyle=linesstyles[i], ms=7,
markevery=mark[i], color=color[i])
plt.axis('equal')
plt.xlabel('x(rad)')
plt.ylabel('y(rad)')
plt.legend()
plt.annotate("linestyle:'" +str(linesstyles[i]) +"'", xy=(0.5, -2.5), va='center', ha='left')
# plt.plot(x, y)
plt.show()
plot线形图标注误差范围
import numpyas np
import matplotlib.pyplotas plt
N =25
np.random.seed(100)
x = np.linspace(0., 10., N)
y = np.sin(x) **2 + np.cos(x)
plt.figure(figsize=(15, 10))
noise = np.random.random(N) *.7 +.4
plt.plot(x, y, ls='-', color='darkgreen', label=r'$y = sin(x)^2+ cos(x)$')
plt.fill_between(x, y + noise, y - noise, alpha=0.5, color='darkgreen')
plt.axis('equal')
plt.fill_between((2, 4), -3.2, 3.2, facecolor='orange')
plt.xlim(0, 10)
plt.ylim(-3, 3)
plt.xlabel('x(rad)')
plt.ylabel('y(rad)')
plt.legend()
plt.show()
网友评论