import numpy as np
import matplotlib.pyplot as plt
# Building random clusters
def cluster(number):
def clusterAroundX(a,b,number):
x = np.random.normal(size=(number,))
return (x-x.min())*(b-a)/(x.max()-x.min())+a
def clusterAroundY(x,m,b):
y = x.copy()
half = (x.max()-x.min())/2
middle = half+x.min()
for i in range(x.shape[0]):
std = (x.max()-x.min())/(2+10*(np.abs(middle-x[i])/half))
y[i] = np.random.normal(x[i]*m+b,std)
return y + np.abs(y.min())
m,b = np.random.randint(-700,700)/100,np.random.randint(0,50)
print(m,b)
f = np.random.randint(0,30)
l = f + np.random.randint(10,50)
x = clusterAroundX(f,l,number)
y = clusterAroundY(x,m,b)
return x,y
我个人认为你的kdeplot解决方案非常好(尽管我会在集群拦截部分做一些工作)。在任何情况下,作为对您的问题的回答,您可以提供hexbin的最小计数(将所有空单元格保留为透明)。这里有一个小函数,可以为任何想要做一些实验的人生成随机的集群(在评论中,您的问题似乎引起了用户的极大兴趣,可以随意使用它):
,使用这段代码,我用散点图绘制了一些聚类图(我通常用这个来做自己的聚类分析,但我想我应该看看seaborn)、hexbin、imshow(更改pcolormesh以获得更多控制)和contourf:
^{pr2}$,结果如下:
{a1}
相关问题 更多 >
编程相关推荐