Matplotlib.pyplot module learning road one

To draw the first picture, the
Matplotlib library provides the matplotlib.pyplot module for graphics processing. For references to this module, the following format requirements are uniformly used: import matplotlib.pyplot as plt, and plt aliases found in the code later, all point to the pyplot module.
**1), plot(), draw points and lines based on coordinate values ​​(x, y).
Function plot(*args, fmt, data=None, **kwargs), parameter instructions:
(1) *args, main Accepts (x, y) coordinate values. Coordinates can be scalar, and x and y can also be value pairs of tuples, lists, and arrays. You can omit the y value, and the function default coordinate value x=y.
(2) fmt, the string'[color][marker][line]', used to specify the line color, mark icon, and line style. For example,'ro–' represents the line is red (represented by r), the coordinate corresponding point is an o icon (represented by o), and the line is a dashed line (represented by -).
(3) data, an object with marked data. If given, you need to provide the label name and draw by specifying the x and y coordinates.
(4) kwargs, specify some attributes of the line in the form of key-value pairs, such as linewidth=2 to specify the line width, color='green' instead of the color specification method in fmt, marker='o' to specify the icon, linestyle=' dashed' specifies the style of the line, and markersize=12 specifies the icon size.

   1、plot(),绘制基于坐标值(x,y)的点、线
(1)用标量坐标,绘制一个点
plt.plot(10,10,'o')    #为了直观直观查看(10,10)处的点,用o图标在该点做了标注
plt.show()   #显示绘图

Insert picture description here

1. Plot(), draw points and lines based on coordinate values ​​(x, y)
(2) Use array coordinates to draw several points

import numpy as np
import matplotlib.pyplot as plt
x = np.array([0,10,5,5])   #这里x,y对应的坐标对包括了(0,5),(10,5),(5,0),(5,10)
y = np.array([5,5,0,10])
plt.plot(x,y,'o')   #这里必须用o图标,否则将产生线
plt.show()

Insert picture description here

x = np.array([0,10,5,5])   
y = np.array([5,5,0,10])
plt.plot(x,y)   #这里没有提供图标,就默认以线形式连接所有点
plt.show()

Insert picture description here
The plot() used for drawing provides a wealth of functions for the color of points and lines, icon markings, and line styles. The usage of these functions is further introduced here. There are two main methods for setting the color, icon, and line type in the plot() parameters. One is to pass string parameters, such as'ro–' for red, o icon, and dotted graphics; the other uses Specify them explicitly in the form of key-value pairs.
1. String settings

x = np.arange(0,5,0.02)
plt.plot(x,np.sin(2*np.pi*x),'go--')
plt.show()

Insert picture description here
The plot() used for drawing provides a wealth of functions for the color of points and lines, icon markings, and line styles. The usage of these functions is further introduced here. There are two main methods for setting the color, icon, and line type in the plot() parameters. One is to pass string parameters, such as'ro–' for red, o icon, and dotted graphics; the other uses Specify them explicitly in the form of key-value pairs.
2. Key-value pair settings

x = np.arange(0,5,0.02)
plt.plot(x,np.sin(2*np.pi*x),color='r',marker='v',linestyle='-')  #r红色,v下三角图标,-实线
plt.show()

Insert picture description here

Guess you like

Origin blog.csdn.net/changshupx/article/details/108577202