Matplot库(python画图工具,用于直观呈现数据)

1. 安装

# 1、安装包 $ pip install matplotlib

# 2、进入python的交互式界面 $ python -i

# 3、使用 matplotlib 的 scatter 方法绘制散点图

测试:

import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [2.1,3.3,1.3,3.6,5.0]
plt.figure(0)
plt.scatter(x,y,color='r',marker='*')
plt.show()
 # 展示散点图

2. 功能和使用注意

Matplotlib是python的2D绘图库。它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形,它可以绘制线图、散点图、等高线图、条形图、柱状图、3D图形、图形动画等等。

pyplot

matplotlib.pyplot是使matplotlib像MATLAB一样工作的命令样式函数的集合。
每个pyplot功能都会对图形进行一些更改:例如,创建图形,在图形中创建绘图区域,在绘图区域中绘制一些线条,用标签装饰绘图等。

绘制条形图 bar

matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align=‘center’, data=None, **kwargs)

实例:回值图像的灰度直方图。

from PIL import  Image
import matplotlib.pyplot as plt
im = Image.open("./data/lenagray.png")
hist = im.histogram()
plt.figure()
plt.bar([i for i in range(len(hist))],hist)
plt.show()

在这里插入图片描述
未完待续

猜你喜欢

转载自blog.csdn.net/beauthy/article/details/105178368