matplotlib.pyplot.plot 参数设置详解以及使用方法

2023-05-16

来自于官网:matplotlib.pyplot.plot — Matplotlib 3.3.2 documentation

matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs)[source]

将 y 与 x 绘制为线条标记。

函数定义:
plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)

点或线节点的坐标由 x,y 给出。

可选的参数 fmt 是定义基本格式(如颜色、标记和线条风格)的方便方法。这是一个快捷的字符串表示法,在下面的 Notes 部分中进行了描述。

plot(x, y)        # 使用默认线条样式和颜色绘制x和y
plot(x, y, 'bo')  # 使用蓝色圆圈标记绘制x和y
plot(y)           # 使用x作为索引数组0..N-1绘制y
plot(y, 'r+')     # 同上,但带有红色加号

您可以使用 Line2D 属性作为关键字参数,以便对外观进行更多控制。行属性和 fmt 可以混合使用。以下两个调用产生相同的结果:

plot(x, y, 'go--', linewidth=2, markersize=12)
plot(x, y, color='green', marker='o', linestyle='dashed',linewidth=2, markersize=12)

当与 fmt 冲突时,关键字参数优先。

标记数据绘图

有一种方便的方法可以用标记数据绘制对象(即可以通过 index obj [‘ y’]访问的数据)。不需要给出 x 和 y 中的数据,你可以在 data 参数中提供对象,然后给出 x 和 y 的标签:

plot(‘xlabel’, ‘ylabel’, data=obj)

支持所有可索引对象。例如,可以是 dict、 panda.DataFrame 或结构化 numpy 数组。

绘制多组数据

最直接的方法就是多次调用 plot。例如:

plot(x1, y1, ‘bo’)
plot(x2, y2, ‘go’)

或者,如果你的数据已经是一个2d 数组,你可以直接传递给 x,y。将为每一列绘制一个单独的数据集。

Example: an array a where the first column represents the x values and the other columns are the y columns:

例如: 一个数组 a,其中第一列代表 x 值,其他列代表 y 列:

plot(a[0], a[1:])

第三种方法是指定多组[ x ]、 y、[ fmt ]组:

plot(x1, y1, ‘g^’, x2, y2, ‘g-’)

在这种情况下,任何附加的关键字参数都应用于所有数据集。此外,此语法不能与数据参数组合使用。

默认情况下,每一行都被分配一个由“样式循环”指定的不同样式。Fmt 和 line 属性参数只有在希望显式偏离这些缺省值时才是必需的。或者,您也可以使用 rcParams[“axes.prop_cycle”] (default: cycler(‘color’, [’#1f77b4’, ‘#ff7f0e’, ‘#2ca02c’, ‘#d62728’, ‘#9467bd’, ‘#8c564b’, ‘#e377c2’, ‘#7f7f7f’, ‘#bcbd22’, ‘#17becf’])).

参数如下:

  • x, y array-like or scalar
    类数组或标量
    The horizontal / vertical coordinates of the data points. x values are optional and default to range(len(y)).
    X 值的水平/垂直坐标是可选的,默认为 range (len (y))。
    Commonly, these parameters are 1D arrays.
    通常,这些参数是一维数组。
    They can also be scalars, or two-dimensional (in that case, the columns represent separate data sets).
    它们也可以是标量或二维的(在这种情况下,列表示单独的数据集)。
    These arguments cannot be passed as keywords.
    这些参数不能作为关键字传递。

  • 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’表示红圈。有关格式字符串的详细说明,请参阅 Notes 部分。
    Format strings are just an abbreviation for quickly setting basic line properties. All of these and more can also be controlled by keyword arguments.
    格式字符串只是快速设置基本行属性的缩写。所有这些以及更多的操作都可以通过关键字参数来控制。
    This argument cannot be passed as keyword.
    此参数不能作为关键字传递。

  • data:indexable object, optional
    An object with labelled data. If given, provide the label names to plot in x and y.
    带有标记数据的对象。如果给定,则提供标记名称,以便在 x 和 y 中进行绘图。

Note

Technically there’s a slight ambiguity in calls where the second label is a valid fmt. plot(‘n’, ‘o’, data=obj) could be plt(x, y) or plt(y, fmt). In such cases, the former interpretation is chosen, but a warning is issued. You may suppress the warning by adding an empty format string plot(‘n’, ‘o’, ‘’, data=obj).
从技术上讲,在第二个标签是有效 fmt 的调用中存在一点模糊性。Plot (’ n’ ,‘ o’ ,data = obj)可以是 plt (x,y)或 plt (y,fmt)。在这种情况下,选择前一种解释,但发出警告。您可以通过添加一个空的格式字符串绘图(’ n’ ,‘ o’ ,” ,data = obj)来抑制警告。

返回值

  • list of Line2D
    A list of lines representing the plotted data.
    代表绘制数据的线列表。

其他参数:

  • scalex, scaley: bool, default: True
    These parameters determine if the view limits are adapted to the data limits. The values are passed on to autoscale_view.
    2d 号线一览表
    表示绘制的数据的行列表。

  • kwargs: Line2D properties, optional
    kwargs are used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color. Example:
    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’)
If you make multiple lines with one plot call, the kwargs apply to all those lines.

下面是可用的 Line2D 属性列表:

属性描述
agg_filtera filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
alphafloat or None
animatedbool
antialiased or aabool
clip_boxBbox
clip_onbool
clip_pathPatch or (Path, Transform) or None
color or ccolor
containsunknown
dash_capstyle{‘butt’, ‘round’, ‘projecting’}
dash_joinstyle{‘miter’, ‘round’, ‘bevel’}
dashessequence of floats (on/off ink in points) or (None, None)
data(2, N) array or two 1D arrays
drawstyle or ds{‘default’, ‘steps’, ‘steps-pre’, ‘steps-mid’, ‘steps-post’}, default: ‘default’
figureFigure
fillstyle{‘full’, ‘left’, ‘right’, ‘bottom’, ‘top’, ‘none’}
gidstr
in_layoutbool
labelobject
linestyle or ls{’-’, ‘–’, ‘-.’, ‘:’, ‘’, (offset, on-off-seq), …}
linewidth or lwfloat
markermarker style string, Path or MarkerStyle
markeredgecolor or meccolor
markeredgewidth or mewfloat
markerfacecolor or mfccolor
markerfacecoloralt or mfcaltcolor
markersize or msfloat
markeveryNone or int or (int, int) or slice or List[int] or float or (float, float) or List[bool]
path_effectsAbstractPathEffect
pickerunknown
pickradiusfloat
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
urlstr
visiblebool
xdata1D array
ydata1D array
zorderfloat

也可以看看

散点
XY 散点 plot 带有大小和/或颜色不同的标记 ( 有时也称为气泡图).

注释

Format Strings
格式化字符串

A format string consists of a part for color, marker and line:
一个格式字符串由一个部分组成,用于颜色、标记和行:

fmt = ‘[marker][line][color]’
Each of them is optional. If not provided, the value from the style cycle is used. Exception: If line is given, but no marker, the data will be a line without markers.
每一个都是可选的。如果没有提供,则使用样式循环中的值。异常: 如果给定行,但没有标记,数据将是一条没有标记的行。

Other combinations such as [color][marker][line] are also supported, but note that their parsing may be ambiguous.
还支持[ color ][ marker ][ line ]等其他组合,但请注意,它们的解析可能是模棱两可的。

标记

线条风格

在这里插入图片描述

Example format strings:

格式字符串示例:

'b'    # 默认形状的蓝色标记
'or'   # 红色圆圈
'-g'   # 绿色实线
'--'   # 带有默认颜色的虚线
'^k:'  # 黑色三角形标记,由虚线连接

颜色

支持颜色缩写:单字母代码

以及索引到默认属性循环的“ CN”颜色。

If the color is the only part of the format string, you can additionally use any matplotlib.colors spec, e.g. full names (‘green’) or hex strings (’#008000’).

如果颜色是格式字符串的唯一部分,那么您可以另外使用任何 matplotlib.colors 规范,例如全名(‘ green’)或十六进制字符串(‘ # 008000’)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

matplotlib.pyplot.plot 参数设置详解以及使用方法 的相关文章

随机推荐

  • Debian——网络/镜像配置

    文章目录 前言一 添加镜像源二 配置网络三 添加阿里云镜像 前言 安装完成之后 xff0c 配置apt源和网络 提示 xff1a 以下是本篇文章正文内容 xff0c 下面案例可供参考 一 添加镜像源 添加ISO文件 xff0c 并连接 ap
  • [Arch iwlist issue] Allocation failed

    之前在学校用 networkmanager 一直不好用 所以试了试手动调试 谁知道再用 iwlist scan时出错 allocation failed 查了一下google 原来是个bug 在无线太多环境下 xff0c 就会出现这种情况
  • 执行pth-winexe报错:ERROR: CreateService failed. NT_STATUS_ACCESS_DENIED.

    问题 xff1a 执行pth winexe时报错 xff1a pth winexe U test aad3b435b51404eeaad3b435b51404ee afc44ee7351d61d00698796da06b1ebf 192 1
  • Windows 远程端口号修改

    远程桌面端口号修改 xff1a 1 计算机 HKEY LOCAL MACHINE SYSTEM CurrentControlSet Control Terminal Server Wds rdpwd Tds tcp 修改PortNumber
  • CCSP2016-1 选座(ticket_chooser)

    CCSP2016 1 选座 xff08 ticket chooser xff09 题目描述 小 B 是一个电影迷 xff0c 只要有时间 xff0c 她就要去观摩最新的大片 但她不喜欢自己在 电脑或其他电子设备上观看 xff0c 而是喜欢去
  • manjaro配置VNC服务

    硬件 xff1a 开发板 xff1a Raspberry Pi 树莓派4B 4G内存 电脑 xff1a win10主机 系统 xff1a manjaro xff1a Raspberry Pi 4 KDE Plasma 21 06 一些准备工
  • iOS开发:关于UISearchController的简单使用

    UISearchController是iOS8以后推出的一个控件 xff0c 在以前的搜索控制器中 xff0c 需要将searchBar于tableView结合使用 有了这个控件之后 xff0c 做搜索控制器就很简单了 效果图 一 需要遵守
  • mac访问win7共享文件夹

    看了网上的一些操作步骤不是太详尽 xff08 对 xff0c 我就是嫌弃它图少 xff09 xff0c 特地制作一个教程来教大家使用mac访问win7的共享文件夹 一 首先我们创建一个用于测试的文件夹 我的台式电脑撤出来一根网线连接在了路由
  • DllNotFoundException

    检查运行dll是否需要其他的dll 这个是报错比较常见的原因 在Unity中报DllNotFoundException有可能是找不到的dll xff0c 它需要引用的其他dll不存在 这个不仅仅是适用于Unity xff0c 大多数dll的
  • Steam游戏的爬取与分析

    Steam游戏的爬取与分析 本文爬取了steam冒险类游戏中热销产品中的7500个游戏进行统计分析 1 首先要先知道网页链接的组成形式 xff1a 2 其次查看我们想要爬取的信息区域 xff1a 3 开始分析 xff1a xff08 1 x
  • word里面的自带编辑器公式怎么转换成math type公式

    这是最近产生的一个问题 xff0c 还在解决中 已解决 这个问题出现主要是因为老板要编书 xff0c 然后一开始是让我们用word自带的编辑器进行编辑 xff0c 现在突然变化 xff0c 让我们全部改成math type格式 首先百度ma
  • Ubuntu 20.04 无法解析软件包文件 /var/lib/dpkg/status

    出现问题 E 无法解析软件包文件 var lib dpkg status 1 W 您可能需要运行 apt get update 来解决这些问题 E 软件包缓存文件损坏了 截图 xff1a 这东西我试了前辈的博客的方法 xff0c 瞎套果然不
  • 如何进入Ubuntu 18.04.1 LTS的根目录

    Ubantu虽然在文件操作上已经有了比较完善的桌面版 xff0c 但是有时候我们想在文件夹找到某一目录还是很难找到的 这个时候我们可以先到根目录下 xff0c 然后在依次查找相应文件夹 另外 xff0c 此操作对于不习惯或者不会使用vi或者
  • Linux下V4L2调用摄像头设备程序崩溃

    问题描述 使用V4L2驱动调用摄像头 xff0c 只能打开一次摄像头 xff0c 第二次打开时程序崩溃 原因 在获取相机数据流时我们一般会使用mmap 来将linux内核空间映射到用户空间 xff0c 在关闭相机时应当调用munmap 解除
  • 时钟恢复(CDR:Clock and Data Recovery)和PLL/DLL

    CDR的作用及应用场景 CDR的主要有两大作用 xff0c 第一是为接收器端各电路提供时钟信号 xff1b 第二是对接收到的信号进行判决 xff0c 便于数据信号的恢复与后续处理 CDR在各种高速PHY RX的应用 xff1a 比如高速ph
  • 【MathType安装】2020年最新将MathType加入word的方法,解决"运行时错误53,MathPage.wll文件未找到"问题

    2020年最新的将MathType加入word的方法 1 找到你的 STARTUP 文件夹2 打开MathType的安装路径3 在word中选择加载4 完成 1 找到你的STARTUP文件夹 这里我提供的方法是下载一个everything搜
  • 【WPF大作业】记一次C#大作业——商家快递包裹系统

    WPF XAML商家快递包裹系统 一 前言二 采用的框架三 程序设计以及架构四 界面一览登录界面主界面统计页面处理订单添加订单物流查询 五 特色功能1 自定义的带花纹的顶栏2 数据库的连接与利用3 选项卡页面4 同步修改表格数据5 任务栏图
  • 熟悉常用的Linux操作和Hadoop操作

    cd命令 xff1a 切换目录 xff08 1 xff09 切换到目录 usr local xff08 2 xff09 去到目前的上层目录 xff08 3 xff09 回到自己的主文件夹 ls命令 xff1a 查看文件与目录 xff08 4
  • 机器学习学习笔记01_matplotlib绘图

    导入需要的库 span class token keyword import span matplotlib span class token punctuation span pyplot span class token keyword
  • matplotlib.pyplot.plot 参数设置详解以及使用方法

    来自于官网 xff1a matplotlib pyplot plot Matplotlib 3 3 2 documentation matplotlib pyplot plot args scalex 61 True scaley 61 T