1.plot()函数

plot()函数会根据列表中的数据尝试绘制出有意义的图形

参数:img1

1
2
3
4
5
6
7
x = np.arange(-6,6,0.1)
#起点:-6,终点:6,步长:0.1
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x,y1)
plt.plot(x,y2)
plt.show()

img2

plt的title()方法:添加图标标题

xlabel()、ylabel()方法:为每条轴设置标题、大小等参数

tick_params()方法:指定刻度标记的大小

1
2
3
4
5
6
7
8
9
10
x = np.arange(-6,6,0.1)#起点:-6,终点:6,步长:0.1
y1 = np.sin(x)
y2 = np.cos(x)
plt.plot(x,y1)
plt.plot(x,y2)
plt.title("Figure 1",fontsize = 18,color = "red")
plt.xlabel("x value",fontsize = 14)
plt.ylabel("y value",fontsize = 14)
plt.tick_params(axis="both",labelsize=10)
plt.show()

img3

2.图像的显示和读取

1
2
3
img = plt.imread('lena.png')
plt.imshow(img)
plt.show()

img4