plt.plot()的使用方法以及参数介绍

前言

偶然的一次操作,对plt.plot()中,仅仅传入了一个列表,然后逻辑就和预想的出现了偏差。

plt.plot()

plt.plot() 参数介绍:

  1. 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的索引。那么我的问题就解决了。
  2. 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。
  3. **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')

拥有的部分参数,如下:

PropertyDescription
agg_filtera filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
alphafloat
animatedbool
antialiasedbool
clip_boxBbox
clip_onbool
clip_path[(Path, Transform)
colorcolor
containscallable
dash_capstyle{‘butt’, ‘round’, ‘projecting’}
dash_joinstyle{‘miter’, ‘round’, ‘bevel’}
dashessequence of floats (on/off ink in points) or (None, None)
drawstyle{‘default’, ‘steps’, ‘steps-pre’, ‘steps-mid’, ‘steps-post’}
figureFigure
fillstyle{‘full’, ‘left’, ‘right’, ‘bottom’, ‘top’, ‘none’}
gidstr
in_layoutbool
labelobject
linestyle{’-’, ‘–’, ‘-.’, ‘:’, ‘’, (offset, on-off-seq), …}
linewidthfloat

参考链接: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()
  • 44
    点赞
  • 250
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值