matplotlib.pyplot.plot()

本文介绍了matplotlib库中的plot()函数,详细阐述了输入数据类型,包括x和y的一维、二维列表或数组组合,并通过示例展示绘图效果。同时,讲解了fmt参数,包括颜色、点标记和线条类型的设定,以及**kwargs参数的优先级规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

matplotlib.pyplot.plot()是matplotlib库中的一个函数,plot有绘图之意,py是python的简写。

matplotlib.pyplot.plot(*args, **kwargs)
    下面是plot函数得两种形式,plot把x与y画成线,或者标记( Plot y versus x as lines and/or markers),第二种形式在一个图中要画出多条线的话可以用,同样也可以重复使用形式一达到目的
plot([x], y, [fmt], data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)其中可以缺少x的数据,会自动以自然数的形式补齐(0,1......n)

1.输入数据类型

    (1)x 和 y 都是一维列表或数组;

    (2)x 是n*1数组或列表,y是一维长度为n的数组或列表;

    (3)x是m*n数组或列表,y是m*1列表或数组。如下例子,画出的图如下。

会产生20个点,十对。

x = [[-0.07816532  0.05068012  0.07786339  0.05285819  0.07823631  0.0644473
   0.02655027 -0.00259226  0.04067226 -0.00936191]
 [ 0.0090156   0.05068012 -0.03961813  0.0287581   0.03833367  0.0735286

  -0.07285395  0.1081111   0.01556684 -0.04664087]]

y = [ 201.12401963  150.05917612]

matplotlib.pyplot.plot(x,y)


2.fmt是shortcut string notation ,其形式为 

    fmt = '[color][marker][line]',颜色,点标记类型,画线类型。

    (1)颜色表:

charactercolor
'b'blue
'g'green
'r'red
'c'cyan
'm'magenta
'y'yellow
'k'black
'w'white

    (2)点类型

characterdescription
'.'point marker
','pixel marker
'o'circle marker
'v'triangle_down marker
'^'triangle_up marker
'<'triangle_left marker
'>'triangle_right marker
'1'tri_down marker
'2'tri_up marker
'3'tri_left marker
'4'tri_right marker
's'square marker
'p'pentagon marker
'*'star marker
'h'hexagon1 marker
'H'hexagon2 marker
'+'plus marker
'x'x marker
'D'diamond marker
'd'thin_diamond marker
'|'vline marker
'_'hline marker

    (3)线条类型

characterdescription
'-'solid line style
'--'dashed line style
'-.'dash-dot line style
':'dotted line style

3.**kwargs包含fmt,如果即在fmt中定义了,然后又重复在**kwargs中定义,那么以**kwargs为准

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 (0.0 transparent through 1.0 opaque)
animatedbool
antialiased or aabool
clip_boxBbox instance
clip_onbool
clip_path[(PathTransform) | Patch | None]
color or cany matplotlib color
containsa callable function
dash_capstyle[‘butt’ | ‘round’ | ‘projecting’]
dash_joinstyle[‘miter’ | ‘round’ | ‘bevel’]
dashessequence of on/off ink in points
drawstyle[‘default’ | ‘steps’ | ‘steps-pre’ | ‘steps-mid’ | ‘steps-post’]
figureFigure instance
fillstyle[‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’]
gidan id string
labelobject
linestyle or ls[‘solid’ | ‘dashed’, ‘dashdot’, ‘dotted’ | (offset, on-off-dash-seq) | '-' | '--' | '-.' | ':' | 'None' | ' ' | '']
linewidth or lwfloat value in points
markerA valid marker style
markeredgecolor or mecany matplotlib color
markeredgewidth or mewfloat value in points
markerfacecolor or mfcany matplotlib color
markerfacecoloralt or mfcaltany matplotlib color
markersize or msfloat
markevery[None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float]
path_effectsAbstractPathEffect
pickerfloat distance in points or callable pick function fn(artist,event)
pickradiusfloat distance in points
rasterizedbool or None
sketch_params(scale: float, length: float, randomness: float)
snapbool or None
solid_capstyle[‘butt’ | ‘round’ | ‘projecting’]
solid_joinstyle[‘miter’ | ‘round’ | ‘bevel’]
transformmatplotlib.transforms.Transform instance
urla url string
visiblebool
xdata1D array
ydata1D array
zorderfloat



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值