目录
1 函数介绍
1.1 scatter()函数
scatter(x, y, s=None, marker=None, camp=None, norm=None, vmin=None,vmax=None,alpha=None, linewidth=None, verts=None, edgecolors=None,hold=None, data=None, **kwargs)
参数名称 | 含义 |
---|---|
s | 点的大小 |
c | 每个点的颜色,可以是数值或数组。这里使用一维数组为每个点指定了一个数值。通过颜色映射表,每个数值都会与一个颜色相对应。默认的颜色映射表中蓝色与最小值对应,红色与最大值对应。当c参数是形状为(N,3)或(N,4)的二维数组时,则直接表示每个点的RGB颜色。 |
marker | 点的形状 |
cmap | 颜色映射 |
vmin,vmax | vmin和vmax被用于与norm一起标准化亮度数据。如果没有,则使用颜色数组的最小值和最大值。 |
alpha | 散点符透明度 |
linewidths | 线条的宽度 |
verts | 如果marker值为0时,verts用来构建形状。 |
edgecolors | 边缘颜色或颜色序列,可选值,默认值:None |
hold | 为了同时在一个图上画多条曲线,可以使用hold关键字 |
1.2 camp用法
cmap=plt.cm.Pastel1
cmap='flag'
2 简单实例:随机产生100个点
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(-1,1,100)
y=np.random.randn(100)
plt.scatter(x,y, marker='o',c=x,cmap=plt.cm.Pastel1)
3 添加标签——plt.text()
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(-1,1,10)
y=np.random.randn(10)
plt.scatter(x,y, marker='o',c=x,cmap=plt.cm.Pastel1)
for i in range(len(x)):
plt.text(x[i], y[i], i+1, fontsize=12, color = "r", style = "italic", weight = "light", verticalalignment='center', horizontalalignment='right', rotation=90)
4 colorbar颜色条:颜色渐变参数的使用
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(-1,1,100)
y=np.random.randn(100)
sc=plt.scatter(x,y, marker='o',c=x,cmap=plt.cm.Pastel1)
plt.colorbar(sc)
5 颜色
cmlist = [‘Accent’, ‘Accent_r’, ‘Blues’, ‘Blues_r’, ‘BrBG’, ‘BrBG_r’, ‘BuGn’, ‘BuGn_r’, ‘BuPu’, ‘BuPu_r’, ‘CMRmap’, ‘CMRmap_r’, ‘Dark2’, ‘Dark2_r’, ‘GnBu’, ‘GnBu_r’, ‘Greens’, ‘Greens_r’, ‘Greys’, ‘Greys_r’, ‘OrRd’, ‘OrRd_r’, ‘Oranges’, ‘Oranges_r’, ‘PRGn’, ‘PRGn_r’, ‘Paired’, ‘Paired_r’, ‘Pastel1’, ‘Pastel1_r’, ‘Pastel2’, ‘Pastel2_r’, ‘PiYG’, ‘PiYG_r’, ‘PuBu’, ‘PuBuGn’, ‘PuBuGn_r’, ‘PuBu_r’, ‘PuOr’, ‘PuOr_r’, ‘PuRd’, ‘PuRd_r’, ‘Purples’, ‘Purples_r’, ‘RdBu’, ‘RdBu_r’, ‘RdGy’, ‘RdGy_r’, ‘RdPu’, ‘RdPu_r’, ‘RdYlBu’, ‘RdYlBu_r’, ‘RdYlGn’, ‘RdYlGn_r’, ‘Reds’, ‘Reds_r’, ‘Set1’, ‘Set1_r’, ‘Set2’, ‘Set2_r’, ‘Set3’, ‘Set3_r’, ‘Spectral’, ‘Spectral_r’, ‘Wistia’, ‘Wistia_r’, ‘YlGn’, ‘YlGnBu’, ‘YlGnBu_r’, ‘YlGn_r’, ‘YlOrBr’, ‘YlOrBr_r’, ‘YlOrRd’, ‘YlOrRd_r’, ‘afmhot’, ‘afmhot_r’, ‘autumn’, ‘autumn_r’, ‘binary’, ‘binary_r’, ‘bone’, ‘bone_r’, ‘brg’, ‘brg_r’, ‘bwr’, ‘bwr_r’, ‘cividis’, ‘cividis_r’, ‘cool’, ‘cool_r’, ‘coolwarm’, ‘coolwarm_r’, ‘copper’, ‘copper_r’, ‘cubehelix’, ‘cubehelix_r’, ‘flag’, ‘flag_r’, ‘gist_earth’, ‘gist_earth_r’, ‘gist_gray’, ‘gist_gray_r’, ‘gist_heat’, ‘gist_heat_r’, ‘gist_ncar’, ‘gist_ncar_r’, ‘gist_rainbow’, ‘gist_rainbow_r’, ‘gist_stern’, ‘gist_stern_r’, ‘gist_yarg’, ‘gist_yarg_r’, ‘gnuplot’, ‘gnuplot2’, ‘gnuplot2_r’, ‘gnuplot_r’, ‘gray’, ‘gray_r’, ‘hot’, ‘hot_r’, ‘hsv’, ‘hsv_r’, ‘inferno’, ‘inferno_r’, ‘jet’, ‘jet_r’, ‘magma’, ‘magma_r’, ‘nipy_spectral’, ‘nipy_spectral_r’, ‘ocean’, ‘ocean_r’, ‘pink’, ‘pink_r’, ‘plasma’, ‘plasma_r’, ‘prism’, ‘prism_r’, ‘rainbow’, ‘rainbow_r’, ‘seismic’, ‘seismic_r’, ‘spring’, ‘spring_r’, ‘summer’, ‘summer_r’, ‘tab10’, ‘tab10_r’, ‘tab20’, ‘tab20_r’, ‘tab20b’, ‘tab20b_r’, ‘tab20c’, ‘tab20c_r’, ‘terrain’, ‘terrain_r’, ‘viridis’, ‘viridis_r’, ‘winter’, ‘winter_r’]
翻转颜色:添加后缀 _r 反转