ris*_*abh 4 python matplotlib heatmap pandas seaborn
假设我们有 x,y 坐标作为输入,其中 x 在范围 (0,300) & y 在范围 (0,400) 我想将所有这些坐标绘制为宽度介于 (0,300) 和之间的矩形网格中的热图(0,400) 之间的高度。
使用 seaborn 或 matplotlib,我可以绘制散点图,但很难将这些点绘制为热图。
x = numpy.random.randint(0, high=50, size=5000, dtype='l')
y = numpy.random.randint(0, high=50, size=5000, dtype='l')
Run Code Online (Sandbox Code Playgroud)
因此,如果我的样本大小是 5000 个点,并且所有点都几乎在 x as (0,50) & y as (0,50) 的范围内,在 300x400 的矩形空间中表示它们应该证明 50x50 空间中的坐标密度最高.
有人可以指导我如何表示这些数据吗?
为了测试和绘制散点图,我使用了 seaborn 的 lmplot 函数。
df = pd.DataFrame()
df['x'] = pd.Series(numpy.random.randint(0, high=320, size=5000, dtype='l'))
df['y'] = pd.Series(numpy.random.randint(0, high=480, size=5000, dtype='l'))
sns.set_style('whitegrid')
sns.lmplot('x','y',data=df,
palette='coolwarm',size=10,fit_reg=False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
似乎这里想要的是一个二维直方图。这可以使用 绘制plt.hist2d。
例子:
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rayleigh(50, size=5000)
y = np.random.rayleigh(50, size=5000)
plt.hist2d(x,y, bins=[np.arange(0,400,5),np.arange(0,300,5)])
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8046 次 |
| 最近记录: |