【发布时间】:2011-07-04 20:23:19
【问题描述】:
我想在 matplotlib 中创建一个 2x3 的 2d 直方图,在每个子图的顶部有一个共享的颜色条和一个 1d 直方图。 AxesGrid 得到了我所有的东西,除了最后一部分。我尝试使用make_axes_locatable 遵循上一页上的"scatter_hist.py" example,将二维直方图添加到每个子图的顶部。代码如下所示:
plots = []
hists = []
for i, s in enumerate(sim):
x = np.log10(s.g['temp']) #just accessing my data
y = s.g['vr']
histy = s.g['mdot']
rmin, rmax = min(s.g['r']), max(s.g['r'])
plots.append(grid[i].hexbin(x, y, C = s.g['mass'],
reduce_C_function=np.sum, gridsize=(50, 50),
extent=(xmin, xmax, ymin, ymax),
bins='log', vmin=cbmin, vmax=cbmax))
grid[i].text(0.95 * xmax, 0.95 * ymax,
'%2d-%2d kpc' % (round(rmin), round(rmax)),
verticalalignment='top',
horizontalalignment='right')
divider = make_axes_locatable(grid[i])
hists.append(divider.append_axes("top", 1.2, pad=0.1, sharex=plots[i]))
plt.setp(hists[i].get_xticklabels(), visible=False)
hists[i].set_xlim(xmin, xmax)
hists[i].hist(x, bins=50, weights=histy, log=True)
#add color bar
cb = grid.cbar_axes[0].colorbar(plots[i])
cb.set_label_text(r'Mass ($M_{\odot}$)')
这会在 divider.append_axes() 函数调用时出错:
AttributeError: 'LocatablePolyCollection' object has no attribute '_adjustable'
有谁知道是否可以使用 axesgrid 方法轻松地将直方图添加到顶部,还是我需要使用不同的方法?谢谢!
【问题讨论】:
-
你还在努力解决这个问题吗?你找到解决办法了吗?
标签: python matplotlib plot