place a colorbar label above horizontal colorbar (instead of below)

matplotlib

Solution

Here's how I did it. The key seems to be to call the colorbar's axes' `set_xlabel` method instead:

cbaxes = fig.add_axes([0.05, 0.05, 0.9, 0.025])
cb = fig.colorbar(cax=cbaxes, mappable=mappable, orientation='horizontal')
cbaxes.set_xlabel(r"$[10^{14}\ molec\,cm^{-2}]$", fontname='Arial',
            fontsize='small', labelpad=-35)
cb.set_ticks(arange(vmin, vmax + 1, 2))
cbytick_obj = plt.getp(cb.ax.axes, 'xticklabels')
plt.setp(cbytick_obj, fontsize='x-small')

Problem

I'm generating a horizontal colorbar with this code: ``` cbaxes = fig.add_axes([0.05, 0.15, 0.9, 0.025]) # setup colorbar axes. cb = fig.colorbar(cax=cbaxes, mappable=mappable, orientation='horizontal',) cb.set_label(r"$[10^{14}\ molec\,cm^{-2}]$", fontname='Arial', fontsize='small') cbytick_obj = plt.getp(cb.ax.axes, 'xticklabels') plt.setp(cbytick_obj, color='r', fontsize='x-small') cb.ax.set_yticks(arange(vmin, vmax, 2), size='small') ``` However, I want the label be printed above the colorbar (instead of below). How can I do that?

Original source