Setting matplotlib colorbar range
matplotlib, python
Solution
Arg. It's always the last thing you try:
quadmesh.set_clim(vmin=0, vmax=15)
works.
Problem
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.arange(20) data = x[:-1,None]+y[None,:-1] fig = plt.gcf() ax = fig.add_subplot(111) X,Y = np.meshgrid(x,y) quadmesh = ax.pcolormesh(X,Y,data) plt.colorbar(quadmesh) #RuntimeError: You must first define an image, eg with imshow #plt.clim(vmin=0,vmax=15) #AttributeError: 'AxesSubplot' object has no attribute 'clim' #ax.clim(vmin=0,vmax=15) #AttributeError: 'AxesSubplot' object has no attribute 'set_clim' #ax.set_clim(vmin=0,vmax=15) plt.show() ``` How do I set the colorbar limits here?