matplotlib learning(1)

import matplotlib.pyplot as plt  # plt 用于显示图片
# import matplotlib.image as mpimg  # mpimg 用于读取图片
import numpy as np

#
# lena = mpimg.imread('houge.jpg')  # 读取和代码处于同一目录下的 lena.png
# # 此时 lena 就已经是一个 np.array 了,可以对它进行任意处理
# lena.shape  # (512, 512, 3)
#
# plt.imshow(lena)  # 显示图片
# plt.axis('off')  # 不显示坐标轴
# plt.show()

# plt.figure()
# plt.plot([1, 0, 9], [4, 5, 6])
# plt.show()


# 1)创建画布(容器层)
plt.figure()
# 2)绘制折线图(图像层)
plt.plot([1, 2, 3, 4, 5, 6, 7], [17, 17, 18, 15, 11, 11, 13])
# 3)显示图像
plt.show()

# # 1)准备数据
# x = np.linspace(-10, 10, 1000)
# y = np.sin(x)
#
# # 2)创建画布
# plt.figure(figsize=(20, 8), dpi=100)
#
# # 3)绘制函数图像
# plt.plot(x, y)
# # 添加网格显示
# plt.grid()
#
# # 4)显示图像
# plt.show()

猜你喜欢

转载自blog.csdn.net/qq_42029527/article/details/83539269