python散点图重叠_matplotlib中重叠点散点图的可视化

您还可以首先计算散射分布的核密度估计值,然后使用密度值为每个散射点指定颜色,从而为点上色。要修改前面示例中的代码:import numpy as np

import matplotlib.pyplot as plt

from scipy.stats import gaussian_kde as kde

from matplotlib.colors import Normalize

from matplotlib import cm

N = 10000

mean = [0,0]

cov = [[2,2],[0,2]]

samples = np.random.multivariate_normal(mean,cov,N).T

densObj = kde( samples )

def makeColours( vals ):

colours = np.zeros( (len(vals),3) )

norm = Normalize( vmin=vals.min(), vmax=vals.max() )

#Can put any colormap you like here.

colours = [cm.ScalarMappable( norm=norm, cmap='jet').to_rgba( val ) for val in vals]

return colours

colours = makeColours( densObj.evaluate( samples ) )

plt.scatter( samples[0], samples[1], color=colours )

plt.show()

不久前,当我注意到scatter函数的文档时,我学会了这个技巧--c : color or sequence of color, optional, default : 'b'c can be a single color format string, or a sequence of color specifications of length N, or a sequence of N numbers to be mapped to colors using the cmap and norm specified via kwargs (see below). Note that c should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. c can be a 2-D array in which the rows are RGB or RGBA, however, including the case of a single row to specify the same color for all points.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值