使用matplotlib的pyplot模块绘图的实现示例
1. 绘制简单图形
使用 matplotlib 的pyplot
模块绘制图形。看一个 绘制sin函数曲线的例子。
import matplotlib.pyplot as plt import numpy as np # 生成数据 x = np.arange(0, 6, 0.1) # 以0.1为单位,生成0到 6 的数据* y = np.sin(x) # 绘制图形 plt.plot(x,y) plt.show()
3. 显示图像
pyplot中还提供了用于显示图像的方法imshow()
。
使用 matplotlib.image
模块的imread()
方法读入图像。
import matplotlib.pyplot as plt from matplotlib.image import imread img = imread(r'D:\plant\plant_1.jpg') # 读入图像,读者根据自己的环境,变更文件名或文件路径(绝对或相对路径,注意路径名不能出现中文) plt.imshow(img) plt.show()
到此这篇关于使用matplotlib的pyplot模块绘图的实现示例的文章就介绍到这了,更多相关matplotlib pyplot模块绘图内容请搜索来客网以前的文章或继续浏览下面的相关文章希望大家以后多多支持来客网!