title: How to add axis labels to imshow plots in python?
body: <p>I copied from <a href="https://glowingpython.blogspot.com/2012/01/how-to-plot-two-variable-functions-with.html" rel="nofollow noreferrer">this website</a> (and simplified) the following code to plot the result of a function with two variables using <code>imshow</code>.</p>
  
  <pre><code>from numpy import exp,arange
  from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show
  
  # the function that I'm going to plot
  def z_func(x,y):
  return (x+y**2)
  
  x = arange(-3.0,3.0,0.1)
  y = arange(-3.0,3.0,0.1)
  X,Y = meshgrid(x, y) # grid of point
  Z = z_func(X, Y) # evaluation of the function on the grid
  
  im = imshow(Z,cmap=cm.RdBu) # drawing the function
  
  colorbar(im) # adding the colobar on the right
  show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mqyG8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mqyG8.png" alt="Plot without axis labels"></a></p>
  
  <p>How do I add axis labels (like <code>'x'</code> and <code>'y'</code> or <code>'var1</code> and <code>'var2'</code>) to the plot? In R I would use <code>xlab = 'x'</code> within (most of) the plotting function(s).</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/27671748/how-to-print-y-axis-label-horizontally-in-a-matplotlib-pylab-chart">im.ylabel('y')</a> with the </p>
  
  <blockquote>
    <p>AttributeError: 'AxesImage' object has no attribute 'ylabel'</p>
  </blockquote>
  
  <p>Beside this, I only found <a href="https://stackoverflow.com/questions/9295026/matplotlib-plots-removing-axis-legends-and-white-spaces">how to remove the axis labels</a>, but not how to add them. </p>
  
  <p>Bonus question: how to have the ticks range from <code>-3</code> to <code>3</code> and not from <code>0</code> to <code>60</code>? </p>