title: How can I know that plt.colorbar must "eat" ax.pcolor?
body: <p>Consider the following code:</p>
  <pre><code>#%%
  Z=np.random.rand(len(X),len(Y))
  X=np.arange(0,10)
  Y=np.arange(0,10)
  
  [fig1,ax1]=plt.subplots()
  pcm=ax1.pcolor(X,Y,Z,cmap='seismic',edgecolors='black')
  plt.colorbar(pcm,extend='max')
  
  #[fig1,ax1]=plt.subplots()
  #ax1.pcolor(X,Y,Z,cmap='seismic',edgecolors='black')
  #plt.colorbar(extend='max')
  </code></pre>
  <p>The uncommented part works while the commented one doesnt. The error returned being:</p>
  <blockquote>
  <p>RuntimeError: No mappable was found to use for colorbar creation. First define a mappable such as an image (with imshow) or a contour set (with contourf).</p>
  </blockquote>
  <p>Looking <a href="https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.colorbar.html" rel="nofollow noreferrer">at the documentation</a>, it is said:</p>
  <blockquote>
  <p>The matplotlib.cm.ScalarMappable (i.e., Image, ContourSet, etc.)
  described by this colorbar. This argument is mandatory for the
  Figure.colorbar method but optional for the pyplot.colorbar function,
  which sets the default to the current image.</p>
  </blockquote>
  <p>In this case, pcm correspond to the return value of ax1.pcolor() which type is &quot;matplotlib.collections.Collection&quot; and doesn't appear in the (non exhaustive) list given by the documentation.</p>
  <p>How could I know from the documentation that I would indeed have to provide to plt.colorbar ax1.pcolor ? I know this from a stackoverflow post. How could I guess this from reading at the documentation ?</p>