Setting matplotlib colorbar range

后端 未结 3 961
死守一世寂寞
死守一世寂寞 2020-12-25 13:15

I would like to set the matplotlib colorbar range. Here\'s what I have so far:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(20)
y = np.a         


        
3条回答
  •  遥遥无期
    2020-12-25 13:15

    Matplotlib 1.3.1 - It looks like the colorbar ticks are only drawn when the colorbar is instanced. Changing the colorbar limits (set_clim) does not cause the ticks to be re-drawn.

    The solution I found was to re-instance the colorbar in the same axes entry as the original colorbar. In this case, axes[1] was the original colorbar. Added a new instance of the colorbar with this designated with the cax= (child axes) kwarg.

               # Reset the Z-axis limits
               print "resetting Z-axis plot limits", self.zmin, self.zmax
               self.cbar = self.fig.colorbar(CS1, cax=self.fig.axes[1]) # added
               self.cbar.set_clim(self.zmin, self.zmax)
               self.cbar.draw_all()
    

提交回复
热议问题