Matplotlib colorbar ticks on left/opposite side

前端 未结 4 1897
孤城傲影
孤城傲影 2020-12-09 08:31

One could generate a vertical colorbar like so(simplified):

import matplotlib.pyplot as plt
import matplotlib as mpl

plt.figure()
c_ax=plt.subplot(111)
cb =          


        
4条回答
  •  忘掉有多难
    2020-12-09 09:32

    I was having the same problem. This situation probably arises when you are setting explicitly the axes of the colorbar. In that case you can easily specify on what side of these axes you get the the ticks and the labels. For example, if you have created an image using imshow

    fig = plt.figure()
    ax = plt.subplot(1, 1, 1)
    im = ax.imshow(data)
    

    You can define the axis for the colorbar, in this example using inset_axes:

    from mpl_toolkits.axes_grid1.inset_locator import inset_axes
    cbaxes = inset_axes(ax, width="7%", height="20%", loc=4)
    

    then add your colorbar

    cb = fig.colorbar(im, cax=cbaxes, ticks=[vmin, vmax], orientation='vertical')
    

    and then control the position of the ticks, etc...

    cbaxes.yaxis.tick_left()
    

提交回复
热议问题