plt.plot()的使用方法以及参数介绍
程序员文章站
2022-03-29 18:41:13
...
前言
偶然的一次操作,对plt.plot()中,仅仅传入了一个列表,然后逻辑就和预想的出现了偏差。
plt.plot()
plt.plot() 参数介绍:
- x, y : array-like or scalar
The horizontal / vertical coordinates of the data points. x values are optional. If not given, they default to [0, …, N-1]. x是可选的,如果x没有,将默认是从0到n-1,也就是y的索引。那么我的问题就解决了。 - fmt : str, optional
A format string, e.g. ‘ro’ for red circles. See the Notes section for a full description of the format strings.定义线条的颜色和样式的操作,如“ro”就是红色的圆圈。
Format strings are just an abbreviation for quickly setting basic line properties. All of these and more can also be controlled by keyword arguments. 这是一个快速设置样式的方法,更多的参数可以参考最后一个keyboard arguments。 - **kwargs : Line2D properties, optional
kwargs are used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.这是一大堆可选内容,可以来里面指定很多内容,如“label”指定线条的标签,“linewidth”指定线条的宽度,等等
Example:
plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)
plot([1,2,3], [1,4,9], 'rs', label='line 2')
拥有的部分参数,如下:
Property | Description |
---|---|
agg_filter | a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array |
alpha | float |
animated | bool |
antialiased | bool |
clip_box | Bbox |
clip_on | bool |
clip_path | [(Path, Transform) |
color | color |
contains | callable |
dash_capstyle | {‘butt’, ‘round’, ‘projecting’} |
dash_joinstyle | {‘miter’, ‘round’, ‘bevel’} |
dashes | sequence of floats (on/off ink in points) or (None, None) |
drawstyle | {‘default’, ‘steps’, ‘steps-pre’, ‘steps-mid’, ‘steps-post’} |
figure | Figure |
fillstyle | {‘full’, ‘left’, ‘right’, ‘bottom’, ‘top’, ‘none’} |
gid | str |
in_layout | bool |
label | object |
linestyle | {’-’, ‘–’, ‘-.’, ‘:’, ‘’, (offset, on-off-seq), …} |
linewidth | float |
参考链接:plt.plot()官网传送门
代码实例
import matplotlib.pyplot as plt
a = [1, 2, 3, 4] # y 是 a的值,x是各个元素的索引
b = [5, 6, 7, 8]
plt.plot(a, b, 'r--', label = 'aa')
plt.xlabel('this is x')
plt.ylabel('this is y')
plt.title('this is a demo')
plt.legend() # 将样例显示出来
plt.plot()
plt.show()