Matplot library (python drawing tool for visual presentation of data)

1. Installation

# 1、安装包 $ pip install matplotlib

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

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

test:

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. Function and use attention

Matplotlib is a 2D plotting library for python. It generates publication-quality graphics in various hardcopy formats and a cross-platform interactive environment . It can draw line graphs, scatter plots, contour graphs, bar graphs, histograms, 3D graphs, graphic animations, and so on.

pyplot

matplotlib.pyplot is a collection of command style functions that make matplotlib work like MATLAB.
Each pyplot function will make some changes to the graph: for example, create a graph, create a drawing area in the graph, draw some lines in the drawing area, decorate the drawing with labels, etc.

Draw bar graph bar

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

Example: the gray histogram of the return image.

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()

Insert picture description here
To be continued

Guess you like

Origin blog.csdn.net/beauthy/article/details/105178368