Plot hist2d with weights

梦想与她 提交于 2019-12-11 04:22:58

问题


I need to plot a hist2d with contour curves and colorbar from a pandas dataframe.

The dataframe has three cols:

x_col, y_col, z_col

I want to plot something like this where z_col are the weights of the hist2d:

But I don't know how to transform the z_col into a weight 1D array from the hist2d function.

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')

来源:https://stackoverflow.com/questions/28150228/plot-hist2d-with-weights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!