绘图函数

plt.plot()函数可以通过相应的参数设置绘图风格。

plt.plot(*args, scalex=True, scaley=True, data=None, **kwargs)

Docstring:
Plot y versus x as lines and/or markers. Call signatures:: plot([x], y, [fmt], *, data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs) The coordinates of the points or line nodes are given by *x*, *y*. The optional parameter *fmt* is a convenient way for defining basic
formatting like color, marker and linestyle. It's a shortcut string
notation described in the *Notes* section below. >>> plot(x, y) # plot x and y using default line style and color
>>> plot(x, y, 'bo') # plot x and y using blue circle markers
>>> plot(y) # plot y using x as index array 0..N-1
>>> plot(y, 'r+') # ditto, but with red plusses You can use `.Line2D` properties as keyword arguments for more
control on the appearance. Line properties and *fmt* can be mixed.
The following two calls yield identical results: >>> plot(x, y, 'go--', linewidth=2, markersize=12)
>>> plot(x, y, color='green', marker='o', linestyle='dashed',
... linewidth=2, markersize=12) When conflicting with *fmt*, keyword arguments take precedence. **Plotting labelled data** There's a convenient way for plotting objects with labelled data (i.e.
data that can be accessed by index ``obj['y']``). Instead of giving
the data in *x* and *y*, you can provide the object in the *data*
parameter and just give the labels for *x* and *y*:: >>> plot('xlabel', 'ylabel', data=obj) All indexable objects are supported. This could e.g. be a `dict`, a
`pandas.DataFame` or a structured numpy array. **Plotting multiple sets of data** There are various ways to plot multiple sets of data. - The most straight forward way is just to call `plot` multiple times.
Example: >>> plot(x1, y1, 'bo')
>>> plot(x2, y2, 'go') - Alternatively, if your data is already a 2d array, you can pass it
directly to *x*, *y*. A separate data set will be drawn for every
column. Example: an array ``a`` where the first column represents the *x*
values and the other columns are the *y* columns:: >>> plot(a[0], a[1:]) - The third way is to specify multiple sets of *[x]*, *y*, *[fmt]*
groups:: >>> plot(x1, y1, 'g^', x2, y2, 'g-') In this case, any additional keyword argument applies to all
datasets. Also this syntax cannot be combined with the *data*
parameter. By default, each line is assigned a different style specified by a
'style cycle'. The *fmt* and line property parameters are only
necessary if you want explicit deviations from these defaults.
Alternatively, you can also change the style cycle using the
'axes.prop_cycle' rcParam. Parameters
----------
x, y : array-like or scalar
The horizontal / vertical coordinates of the data points.
*x* values are optional and default to `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. 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*. .. 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)`. Other Parameters
----------------
scalex, scaley : bool, optional, default: True
These parameters determined if the view limits are adapted to
the data limits. The values are passed on to `autoscale_view`. **kwargs : `.Line2D` properties, optional
*kwargs* are used to specify properties like a line label (for
auto legends), linewidth, antialiasing, marker face color.
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') If you make multiple lines with one plot command, the kwargs
apply to all those lines. Here is a list of available `.Line2D` properties: 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 or aa: bool
clip_box: `.Bbox`
clip_on: bool
clip_path: [(`~matplotlib.path.Path`, `.Transform`) | `.Patch` | None]
color or c: 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 or ds: {'default', 'steps', 'steps-pre', 'steps-mid', 'steps-post'}, default: 'default'
figure: `.Figure`
fillstyle: {'full', 'left', 'right', 'bottom', 'top', 'none'}
gid: str
in_layout: bool
label: object
linestyle or ls: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
linewidth or lw: float
marker: marker style
markeredgecolor or mec: color
markeredgewidth or mew: float
markerfacecolor or mfc: color
markerfacecoloralt or mfcalt: color
markersize or ms: float
markevery: None or int or (int, int) or slice or List[int] or float or (float, float)
path_effects: `.AbstractPathEffect`
picker: float or callable[[Artist, Event], Tuple[bool, dict]]
pickradius: float
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: `matplotlib.transforms.Transform`
url: str
visible: bool
xdata: 1D array
ydata: 1D array
zorder: float Returns
-------
lines
A list of `.Line2D` objects representing the plotted data.
颜色设置

通过color参数设置。

#标准颜色名称
plt.plot(x, np.sin(x-0), color='blue')

#缩写颜色代码(rgbcmyk)
plt.plot(x, np.sin(x-1), color='g')

#范围在0~1的灰度值
plt.plot(x, np.sin(x-2), color='0.75')

#十六进制(RRGGBB, 00~FF)
plt.plot(x, np.sin(x-3), color='#FFDD44')

#RGB元组,范围在0~1
plt.plot(x, np.sin(x-4), color=(1.0, 0.2, 0.3))

#HTML颜色名称
plt.plot(x, np.sin(x-5), color='chartreuse')

线条风格设置

通过linesyle设置线条风格。

#实线
plt.plot(x, np.sin(x-0), linestyle='solid')
# plt.plot(x, np.sin(x-0), linestyle='-')
#虚线
plt.plot(x, np.sin(x-1), linestyle='dashed')
# plt.plot(x, np.sin(x-0), linestyle='--')
#点划线
plt.plot(x, np.sin(x-2), linestyle='dashdot')
# plt.plot(x, np.sin(x-0), linestyle='-.')
#实点线
plt.plot(x, np.sin(x-3), linestyle='dotted')
# plt.plot(x, np.sin(x-0), linestyle=':')

组合设置

将linestyle和color编码组合起来。

#绿色实线
plt.plot(x, x + 0, '-g')
#青色虚线
plt.plot(x, x + 1, '--c')
#黑色点划线
plt.plot(x, x + 2, '-.k')
#红色实点线
plt.plot(x, x + 3, ':r')

Matplotlib绘图设置---图形颜色和风格调整的更多相关文章

  1. matplotlib学习——设置线条颜色及形状

    在图形表示中,不同的画布或画布中不同的函数,我们常常要用不同的形状或颜色来区分开,这里小编向大家介绍这些参数的表示方法: 一.控制颜色 b--blue             c--cyan(青色)  ...

  2. Python matplotlib绘图设置图例

    一.语法简介 plt.legend(loc=2,edgecolor='red',facecolor='green',shadow='True',fontsize=10) #edgecolor 图例边框 ...

  3. Python matplotlib绘图设置坐标轴的标题

    一.语法简介 plt.xlabel("销售月份",fontsize=16,color='red',fontweight='bold',loc='center',background ...

  4. 【划重点】Python matplotlib绘图设置坐标轴的刻度

    一.语法简介 plt.xticks(ticks,labels,rotation=30,fontsize=10,color='red',fontweight='bold',backgroundcolor ...

  5. 【原】在Matplotlib绘图中添加Latex风格公式

    Matplotlib绘图的过程中,可以为各个轴的Label,图像的Title.Legend等元素添加Latex风格的公式. 只需要在Latex公式的文本前后各增加一个$符号,Matplotlib就可以 ...

  6. matplotlib 设置图形大小时 figsize 与 dpi 的关系

    matplotlib 中设置图形大小的语句如下: fig = plt.figure(figsize=(a, b), dpi=dpi) 其中: figsize 设置图形的大小,a 为图形的宽, b 为图 ...

  7. matplotlib绘图教程,设置标签与图例

    大家好,欢迎大家阅读周四数据处理专题,我们继续介绍matplotlib作图工具. 在上一篇文章当中我们介绍了matplotlib这个包当中颜色.标记和线条这三种画图的设置,今天我们同样也介绍三种新的设 ...

  8. UI设计篇·入门篇·绘制简单自定义矩形图/设置按钮按下弹起颜色变化/设置图形旋转

    Android的基本控件和图形有限,难以满足所有的实际需要和设计需求,好在Android给出了相对完善的图形绘制和自定义控件的API,利用这些API,可以基本满足设计的需求. 自定义图像和控件的方法: ...

  9. Matplotlib绘图双纵坐标轴设置及控制设置时间格式

    双y轴坐标轴图 今天利用matplotlib绘图,想要完成一个双坐标格式的图. fig=plt.figure(figsize=(20,15)) ax1=fig.add_subplot(111) ax1 ...

  10. 使用ECharts制作图形时,如何设置指定图形颜色?

    使用ECharts制作图形时,图形颜色是默认的颜色,有时需求需要指定图形颜色,这就需要自己去设置. 在option下的series属性中设置itemStyle,如下所示: itemStyle: { n ...

随机推荐

  1. 【华为机试ACM基础#02】从单向链表中删除指定值的节点、输出单向链表中倒数第k个节点(熟悉链表的输入方式)

    从单向链表中删除指定值的节点 输入一个单向链表和一个节点的值,从单向链表中删除等于该值的节点,删除后如果链表中无节点则返回空指针. 链表的值不能重复. 构造过程,例如输入一行数据为: 6 2 1 2 ...

  2. error LNK2019: unresolved external symbol _CrtDbgReport referenced in function xxxx

    现象 在用C++调试dll动态库的时候汇报上述错误,我用VS2015编译的DEBUG版本动态库,实际在VS2019中调试 解决方法 在工程属性中做出如下选择,代码生成->多线程调试DLL ,出现 ...

  3. 【Azure Redis】Redis导入备份文件(RDB)失败的原因

    问题描述 在测试Azure Redis的导入/导出备份文件的功能中,突然发现在Redis 4.0上导入的时候,一直报错. 问题解答 因为门户上只是显示导入失败,没有任何错误消息说明.根据常理推断,Re ...

  4. ASP.NET Core 从入门到精通-资源收集导航

    ASP.NET Core 从入门到精通-资源收集导航 目录 ASP.NET Core 从入门到精通-资源收集导航 学习路线 学习路线资源导航大全 1,介绍 2,入门 3,教程 创建 Razor 页面 ...

  5. 牛客周赛 Round 31(A~F)

    目录 A B C D E F A #include <bits/stdc++.h> #define int long long #define rep(i,a,b) for(int i = ...

  6. APP限制录屏怎么办?如何绕过APP录屏限制和截图限制-支持安卓和IOS

    简要:互联网越来越发达,衍生了很多形形色色的app,商家为了防止app资源被传播,因此在用户截取屏幕操作或者录屏操作时会警告用户并前会禁止用户的这一操作行为. 那么有没有办法解决呢?有人说可以用投屏. ...

  7. [学习笔记] Rocket.Chat 安装与设置启动项

    这篇文章主要介绍手动安装的方式来安装Rocket.Chat,在Rocket.Chat官方有三种安装方式, 面向开发人员的直接使用meteor部署 传统的源码编译安装 Docker方式部署 接下来分别介 ...

  8. @hook:updated="$common.lib.consoleInfo('updated')" vue外层插入监听事件

    @hook:updated="$common.lib.consoleInfo('updated')" vue外层插入监听事件

  9. 逆向通达信Level-2 续六 (调试pad控件)

    调试终端面版单元, 以及宿主窗口 调试大数据面版单元, 以及宿主窗口 逆向通达信Level-2 续十一 (无帐号登陆itrend研究版) 逆向通达信Level-2 续十 (trace脱壳) 逆向通达信 ...

  10. 3DCAT首届行业生态交流会|爱智慧科技有限公司CEO梁新刚:工业元宇宙的”形“与”神“

    2021年12月17日下午,由深圳市瑞云科技有限公司主办,深圳市虚拟现实产业联合会协办的 云XR如何赋能元宇宙--3DCAT实时云渲染首届行业生态合作交流会 圆满落幕.此次活动围绕"云XR如 ...