matplotlib中plt.scatter()与plt.plot()参数详解

scatter绘制散点,plot绘制经过点的曲线

scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None,edgecolors=None, hold=None, data=None, **kwargs)

x,y:输入数据,array_like,shape(n,)
s:点的大小
  标量或array_like,shape(n,),可选大小以点数^ 2。默认是rcParams ['lines.markersize'] ** 2
c:点的颜色
  顺序或颜色顺序,可选,默认:‘b’ c可以是单个颜色格式的字符串,也可以是一系列颜色 规范的长度为N,或一系列N数字 使用通过kwargs指定的cmapnorm映射到颜色(见下文)。请注意,c不应该是单个数字RGB或RGBA序列,因为这与数组无法区分值将被彩色映射。 c可以是一个二维数组,其中的行是RGB或RGBA,但是,包括单个的情况行为所有点指定相同的颜色。
marker:点的形状  
    〜matplotlib.markers.MarkerStyle,可选,默认值:‘o’ 请参阅〜matplotlib.markers以获取有关不同的更多信息标记分散支持的样式。 marker可以是该类的实例或特定文本的简写
标记。
cmap〜matplotlib.colors.Colormap,可选,默认:无 一个〜matplotlib.colors.Colormap实例或注册名称。cmap仅在c是浮点数组时使用。如果没有,默认为rcimage.cmap
norm〜matplotlib.colors.Normalize,可选,默认:无 〜matplotlib.colors.Normalize实例用于缩放亮度数据为0,1。norm只有在c是一个数组时才被使用 彩车。如果None',则使用默认值:func:normalize。 **vmin**,vmax:标量,可选,默认值:无vminvmaxnorm结合使用来标准化亮度数据。如果其中任何一个都是无’,那么最小和最大的 使用颜色数组。请注意,如果你通过一个“规范”实例,你的vminvmax的设置将被忽略。
alpha:标量,可选,默认值:无 alpha混合值,介于0(透明)和1(不透明)之间,
linewidths:标量或array_like,可选,默认值:无 如果无,则默认为(lines.linewidth,)。
verts:(x,y)的序列,可选 如果marker为None,这些顶点将用于 构建标记。标记的中心位于在(0,0)为标准化单位。整体标记重新调整 由s完成。
edgecolors :颜色或颜色顺序,可选,默认值:无如果无,则默认为’face’

如果’face’,边缘颜色将永远是相同的颜色。 如果它是’none’,补丁边界不会 被画下来。对于未填充的标记,“edgecolors” kwarg 被忽视并被迫在内部“面对”。

备注:
1.点的形状marker参数如下

2.点的颜色c参数如下:
在这里插入图片描述

plt.plot()

plt.plot() 参数介绍:

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的索引。那么我的问题就解决了。
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。
**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’)

拥有的部分参数,如下:
matplotlib中plt.scatter()与plt.plot()参数详解_第1张图片
matplotlib中plt.scatter()与plt.plot()参数详解_第2张图片

代码实例

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()

你可能感兴趣的:(人工智能,Python自学教程)