繁体   English   中英

如何在 matplotlib 中的颜色条上增加 label 填充

[英]How to increase label padding on a colorbar in matplotlib

我有一个 plot 是用以下代码制成的:

fig = plt.figure(figsize = (10 , 11))
gs = GridSpec(nrows=12, ncols=10)
gs.update(wspace = 0, hspace = 0.5)

ax0 = fig.add_subplot(gs[2:12, 0:10])
ax0.set_ylabel(r"$Pa\beta/H\alpha$")
ax0.set_xlabel(r"$H\alpha/H\beta$")
y0 = ax0.scatter(dcmergedf['HA_FLUX']/dcmergedf['HB_FLUX'], dcmergedf['PAB_FLUX']/dcmergedf['HA_FLUX'], s=300, c = dcmergedf['td_lmass'], cmap='coolwarm')
ax0.errorbar(dcmergedf['HA_FLUX']/dcmergedf['HB_FLUX'] ,  dcmergedf['PAB_FLUX']/dcmergedf['HA_FLUX']  , xerr = dcmergedf['BALMER_ERR'] , yerr = dcmergedf['PABHA_ERR'], c = 'black' , linestyle = 'None')
ax0.plot(dustcurvesdf['HAHB'] , dustcurvesdf['PABHA_CALZ00']*5 , c = 'blue' , label = '5 x Calzetti+00' , linestyle = '--')
ax0.plot(dustcurvesdf['HAHB'] , dustcurvesdf['PABHA_CALZ00'] , c = 'blue' , label = 'Calzetti+00')

ax0.plot(dustcurvesdf['HAHB'] , dustcurvesdf['PABHA_GORD03'] , c = 'green' , linestyle = ':' , label = 'Gordon+03')
ax0.plot(dustcurvesdf['HAHB'] , dustcurvesdf['PABHA_FITZ99'] , c = 'orange' , linestyle = '-.' , label = 'Fitzpatrick+99')

ax0.axis([1 , 10 , 0 , 1.8])
#ax0.legend(loc = 'upper left')
ax3 = fig.add_subplot(gs[0:1,1:9])
fig.colorbar(y0,ax3,use_gridspec=True,orientation='horizontal' ,  label = r'log$M_{\odot}$')
ax3.xaxis.set_label_position('top')
#ax3.xaxis.set_label_pad(0.1)

生成的 plot 看起来像用彩条绘制

如何增加颜色条 label 上的填充,使其不与颜色条本身重叠?

您可以将垂直对齐设置为'bottom' (默认为'basement' ):

ax3.xaxis.get_label().set_verticalalignment('bottom')

左:默认(基线),右下:

基线底部

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM