title: Plotting a masked surface plot using python, numpy and matplotlib
body: <p>I'm plotting a surface using matplotlib 1.1.0.</p>
  
  <p>The plot Z axis is masked like so:</p>
  
  <pre><code>Zm = ma.masked_where((abs(z_grid) &lt; 1.09) &amp; (abs(z_grid) &gt; 0.91), (z_surface))
  surf = ax.plot_surface(X, Y,Zm, rstride=2, cstride=2, cmap=colors,linewidth=0, antialiased=False)
  </code></pre>
  
  <p>But I'm not seeing the mask applied on the plot. I plotted the mask itself as a subplot</p>
  
  <pre><code>surf = ax.plot_surface(X, Y,ma.getmask(Zm), rstride=2, cstride=2, cmap=colors,linewidth=0, antialiased=False)
  </code></pre>
  
  <p>Which worked, so I know my mask does actually contain True values.</p>
  
  <p>Full code:</p>
  
  <pre><code>from pylab import *
  import matplotlib.pyplot as plt
  from matplotlib.widgets import Button
  import numpy
  from mpl_toolkits.mplot3d.axes3d import Axes3D
  from  matplotlib import patches
  from matplotlib.figure import Figure
  from matplotlib import rcParams
  
  
  fig = plt.figure(figsize=plt.figaspect(0.5))
  ax = fig.add_subplot(1, 2, 1,projection='3d')
  
  pole_positions_orig = [-0.6+0.73j];
  zero_positions_orig = [0.29-0.41j];
  
  surface_limit = 1.7;
  min_val = -surface_limit;
  max_val = surface_limit;
  
  surface_resolution = 0.0333;
  
  X = numpy.arange(min_val,max_val,surface_resolution)
  Y = numpy.arange(min_val,max_val,surface_resolution)
  X, Y = numpy.meshgrid(X, Y)
  
  z_grid = X + Y*1j;
  z_surface = z_grid*0;
  
  pole_positions = numpy.round(pole_positions_orig,1) + surface_resolution/2+(surface_resolution/2)*1j;
  zero_positions = numpy.round(zero_positions_orig,1) + surface_resolution/2 +(surface_resolution/2)*1j;
  
  for k in range(0, len(zero_positions)):
      z_surface = z_surface + 20*log10((z_grid - zero_positions[k].real - zero_positions[k].imag*1j));
      z_surface = z_surface + 20*log10((z_grid - zero_positions[k].real + zero_positions[k].imag*1j));
  
  for k in range(0, len(pole_positions)):
      z_surface = z_surface - 20*log10((z_grid - pole_positions[k].real - pole_positions[k].imag*1j));
      z_surface = z_surface - 20*log10((z_grid - pole_positions[k].real + pole_positions[k].imag*1j));    
  
  
  colors = cm.jet;
  colors.set_bad('k');
  
  
  Zm = ma.masked_where((abs(z_grid) &lt; 1.09) &amp; (abs(z_grid) &gt; 0.91), (z_surface))
  
  z_surface = Zm;
  
  surf = ax.plot_surface(X, Y,z_surface, rstride=2, cstride=2, cmap=colors,linewidth=0, antialiased=False)
  
  
  ticks = [-1, 1]; 
  z_ticks = [-30,-20,-10,0,10,20,30]; 
  ax.set_xticks(ticks);
  ax.set_yticks(ticks);   
  ax.set_zticks(z_ticks);
  
  ax.set_xlabel('Re')
  ax.set_ylabel('Im')
  ax.set_zlabel('Mag(db)',ha='left')
  plt.setp(ax.get_zticklabels(), fontsize=7)
  plt.setp(ax.get_xticklabels(), fontsize=7)  
  plt.setp(ax.get_yticklabels(), fontsize=7)
  
  ax = fig.add_subplot(1, 2, 2,projection='3d')
  surf = ax.plot_surface(X, Y,ma.getmask(z_surface), rstride=2, cstride=2, cmap=colors,linewidth=0, antialiased=False)
  
  ax.grid(b=None);
  show();
  </code></pre>
  
  <p>This is what I have:</p>
  
  <p><img src="https://i.stack.imgur.com/AD9n6.png" alt="python plot"></p>
  
  <p>This is what I want (from matlab):</p>
  
  <p><img src="https://i.stack.imgur.com/38qwT.png" alt="matlab plot"></p>
  
  <p>What am I missing?</p>