我需要hist2d
从熊猫数据框中绘制带有轮廓曲线和颜色条的曲线。
数据框具有三个列:
x_col, y_col, z_col
我想绘制这样的东西,其中z_col
的权重是hist2d
:
但我不知道如何将 z_col 从 hist2d 函数转换为权重一维数组。
fdf = df.groupby([valueX, valueY], as_index=False).mean().sort([valueX, valueY])
x = fdf[valueX]
y = fdf[valueY]
z = fdf[valueZ]
(... axes instantiation)
bins = 100
counts, xbins, ybins, image = axes.hist2d(x, y, bins=bins, normed=True, weights=z)
axes.contour(counts, extent=[xbins.min(), xbins.max(), ybins.min(), ybins.max()], linewidths=3)
pc = axes.pcolor(counts, cmap=cm.jet)
fig.colorbar(pc)
axes_x.hist(x, bins=bins)
axes_y.hist(y, bins=bins, orientation='horizontal')