通过help()查看matplotlib.pyplot的介绍,翻译如下 Help on function plot in module matplotlib.pyplot: plot(*args, **kwargs) 1.以x、y绘制图像. 调用方式:: plot([x], y, [fmt], data=None, **kwargs) plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs) 点或线的坐标由 *x*, *y*给出. 可选参数 *fmt* 是定义图像基本格式(如颜色、标记、线条样式)的快捷方式, 其为一个字符串,具体内容在下文详述. 也可以使用`.line2d`属性作为关键字参数对外观进行更多的控制。`.line2d`属性和*fmt*可以混合使用。以下两个调用具有相同结果: >>> plot(x, y, 'go--', linewidth=2, markersize=12) >>> plot(x, y, color='green', marker='o', linestyle='dashed', linewidth=2, markersize=12) 当 *fmt* 与 **kwargs 发生冲突时,以 **kwargs 为准 (译者注:用jupter实测是以后写的参数为准) 2.绘制有标签的数据 plot可以方便地绘制带标签的数据对象(即可以通过索引``obj['y']``访问的数据).为此需要在 *data* 参数中提供对象,而不是在 *x*和 *y* 中提供数据,而为 *x* 和 *y* 提供标签: >>> plot('xlabel', 'ylabel', data=obj) 该方式支持所有可索引的对象.包括 `dict`, `pandas.DataFame` 或结构化的数组。 3.绘制(同一幅图中的)多组数据 有以下不同的方式可以绘制多组数据. - 最直接的方法是多次调用`plot`. 例如: >>> plot(x1, y1, 'bo') >>> plot(x2, y2, 'go') - 如果数据是一个二维数组,可以将其直接传递给*x*, *y*.将为二维数组每列单独绘制图像. 例如: 数组 ``a``其中第一列表示 *x* 值,其他列表示 *y* : >>> plot(a[0], a[1:]) - 第三种方法是指定多组 *[x]*, *y*, *[fmt]*:: >>> plot(x1, y1, 'g^', x2, y2, 'g-') 在这种方式下,任何其他关键字参数(译者注:**kwargs)都适用于所有数据集。此外,此方式不能与*data*参数组合使用。 默认情况下,每组图像通过“样式循环”被分配一个不同样式。当需要与默认值不同的样式时,*fmt* 和 line属性参数才是必需的。或者,也可以使用'axes.prop_cycle' rcParam 更改样式循环方式. 参数 ---------- x, y : 类数组array-like 或 标量scalar 分别为数据的横/纵坐标。*x* 可选的。如果没有给出,默认为 ``[0, ..., N-1]``. 通常,这些参数是长度为N的数组.但也支持标量(相当于具有常量值的数组). 参数也可以是二维的,此时二维数组各列表示单独的数据集。 fmt : 字符串, 可选 表示图像样式的字符串, 比如'ro' 代表红色线条圆圈标记. 所有描述参考 *注释* fmt提供了快速设置基本属性的方式.所有以及更多属性可以由关键字参数(**kwargs)控制. data : 可索引对象, 可选 带标记的数据对象。如果给定,请在*x*和*y*中提供要绘制的标签名称。. .. 注:: 技术上讲当第二个标签也可以表示有效的 *fmt*参数时调用会存在歧义. 如`plot('n', 'o', data=obj)` 可以解释为 `plt(x, y)` 或 `plt(y, fmt)`. 在这种情况下,会选择第一种解释方式, 但会给出警告. 为了消除警告可以添加一个空的*fmt*参数,如`plot('n', 'o', '', data=obj)`. 其它参数 ---------------- scalex, scaley : 布尔型, 可选, 默认: True 这些参数决定了视图边界是否适应数据边界. T其值将传递给 `autoscale_view`. **kwargs : `.Line2D` 属性, 可选 *kwargs* 用于指定各线条标签(用于自动图例)、线条宽度、抗锯齿、标记颜色等属性. 如:: >>> plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2) >>> plot([1,2,3], [1,4,9], 'rs', label='line 2') 如果用同一个plot指令绘制多个图像, kwargs参数将适用于所用图像. 以下为所用可用的的 `.Line2D` 属性: 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 (0.0 transparent through 1.0 opaque) animated: bool antialiased or aa: bool clip_box: a `.Bbox` instance clip_on: bool clip_path: [(`~matplotlib.path.Path`, `.Transform`) | `.Patch` | None] color or c: any matplotlib color contains: a callable function dash_capstyle: ['butt' | 'round' | 'projecting'] dash_joinstyle: ['miter' | 'round' | 'bevel'] dashes: sequence of on/off ink in points drawstyle: ['default' | 'steps' | 'steps-pre' | 'steps-mid' | 'steps-post'] figure: a `.Figure` instance fillstyle: ['full' | 'left' | 'right' | 'bottom' | 'top' | 'none'] gid: an id string label: object linestyle or ls: ['solid' | 'dashed', 'dashdot', 'dotted' | (offset, on-off-dash-seq) | ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` | ``' '`` | ``''``] linewidth or lw: float value in points marker: :mod:`A valid marker style <matplotlib.markers>` markeredgecolor or mec: any matplotlib color markeredgewidth or mew: float value in points markerfacecolor or mfc: any matplotlib color markerfacecoloralt or mfcalt: any matplotlib color markersize or ms: float markevery: [None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float] path_effects: `.AbstractPathEffect` picker: float distance in points or callable pick function ``fn(artist, event)`` pickradius: float distance in points rasterized: bool or None sketch_params: (scale: float, length: float, randomness: float) snap: bool or None solid_capstyle: ['butt' | 'round' | 'projecting'] solid_joinstyle: ['miter' | 'round' | 'bevel'] transform: a :class:`matplotlib.transforms.Transform` instance url: a url string visible: bool xdata: 1D array ydata: 1D array zorder: float 返回 ------- lines 表示绘制图像的`.Line2D` 对象列表. 或 -------- scatter : 带有可变大小和/或颜色标记的xy散点图(有时也称为气泡图)). 注释 ----- **Format Strings** 样式字符串有颜色、标记和线形组成:: fmt = '[color][marker][line]' 其中各项均为可选. 若没有提供其值从样式循环中去. 但是如果提供了 ``line`` 但是没有 ``marker``,将绘制没有标记的线条. **颜色** 支持以下颜色缩写: ============= =============================== 字符 颜色 ============= =============================== ``'b'`` 蓝色 ``'g'`` 绿色 ``'r'`` 红色 ``'c'`` 青色 ``'m'`` 品红 ``'y'`` 黄色 ``'k'`` 黑色 ``'w'`` 白色 ============= =============================== 如果格式字符串只有颜色部分,还可以使用任何“matplotlib.colors”规范,例如全名(``'green'``)或十六进制字符串(``'#008000'``)(译者注:即RGB表示). **标记** ============= =============================== 字符 标记形状 ============= =============================== ``'.'`` 点 ``','`` 像素(译者注:大概就是很小的点) ``'o'`` 圆圈 ``'v'`` 指向下的三角 ``'^'`` 指向上的三角 ``'<'`` 指向左的三角 ``'>'`` 指向右的三角 ``'1'`` 指向下的三叉形(译者注:大概就和奔驰的标志一样) ``'2'`` 指向上的三叉形 ``'3'`` 指向左的三叉形 ``'4'`` 指向右的三叉形 ``'s'`` 方形 ``'p'`` 五边形 ``'*'`` 五角星形 ``'h'`` 六边形1 ``'H'`` 六边形2(译者注:两者角的指向不同) ``'+'`` +标记 ``'x'`` x标记 ``'D'`` 钻石形(译者注:大概就是朝向不同的方形) ``'d'`` 瘦的钻石形(译者注:就是菱形) ``'|'`` |形 ``'_'`` _形 ============= =============================== **线形** ============= =============================== 字符 线形 ============= =============================== ``'-'`` 实线 ``'--'`` 虚线 ``'-.'`` 点划线 ``':'`` 点 ============= =============================== 样例:: 'b' # blue markers with default shape 'ro' # red circles 'g-' # green solid line '--' # dashed line with default color 'k^:' # black triangle_up markers connected by a dotted line .. note:: In addition to the above described arguments, this function can take a **data** keyword argument. If such a **data** argument is given, the following arguments are replaced by **data[<arg>]**: * All arguments with the following names: 'x', 'y'.
[Python学习]Python绘图matplotlib——plot
最新推荐文章于 2024-01-18 00:26:19 发布