Python数据可视化——散点图、添加标签、颜色选取

目录

1 函数介绍

1.1 scatter()函数

1.2 camp用法

2 简单实例:随机产生100个点

3 添加标签——plt.text()

4 colorbar颜色条:颜色渐变参数的使用

5 颜色


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)
scatter()函数的参数
参数名称含义
s点的大小
c每个点的颜色,可以是数值或数组。这里使用一维数组为每个点指定了一个数值。通过颜色映射表,每个数值都会与一个颜色相对应。默认的颜色映射表中蓝色与最小值对应,红色与最大值对应。当c参数是形状为(N,3)或(N,4)的二维数组时,则直接表示每个点的RGB颜色。
marker点的形状
cmap颜色映射
vmin,vmaxvmin和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)

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0pfX2FyaWVz,size_16,color_FFFFFF,t_70

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)  

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0pfX2FyaWVz,size_16,color_FFFFFF,t_70

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 反转

参考颜色:https://matplotlib.org/2.0.2/users/colormaps.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值