
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 barcb = 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方法轻松地将直方图添加到顶部,或者我是否需要使用不同的方法?谢谢!
解决方法@H_404_23@ 您应该在调用divIDer.append_axes时将shareessubplot(具有_adjustable属性)的实例提供给sharex关键字.而不是这个,您将hexbin的返回值赋予此关键字参数,该参数是LocatablepolyCollection的一个实例.因此,如果在调用divIDer.append_axes时将sharex = plots [i]替换为sharex = grID [i],则代码应该可以正常工作.
@H_404_34@ 总结以上是内存溢出为你收集整理的python – 将共享轴图添加到matplotlib中的AxesGrid图全部内容,希望文章能够帮你解决python – 将共享轴图添加到matplotlib中的AxesGrid图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)