title: Python netcdf cartopy - Plotting a selection of data
body: <p>I have a netcdf file ('test.nc'). The variables of the netcdf file are the following:</p>
  <pre><code>variables(dimensions): float64 lon(lon), float64 lat(lat), int32 crs(), int16 Band1(lat,lon)
  </code></pre>
  <p>I am interested in the ´Band1´ variable.
  Using cartopy, I could plot the data using the following code:</p>
  <pre><code>import numpy as np
  import pandas as pd
  import gzip
  from netCDF4 import Dataset,num2date
  import time
  import matplotlib.pyplot as plt
  import os 
  import matplotlib as mplt
  #mplt.use('Agg')
  import cartopy.crs as ccrs
  import cartopy.feature as cfea
  import matplotlib.pyplot as plt
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  
  projection=ccrs.PlateCarree()
  bbox=[-180,180,-60,85];creg='glob'
  mplt.rc('xtick', labelsize=9) 
  mplt.rc('ytick', labelsize=9)
  
  nc = Dataset('test.nc','r')
  lat = nc.variables['lat'][:]
  lon = nc.variables['lon'][:]
  kopi= (nc.variables['Band1'][:,:])
  nc.close()
  
  fig=plt.figure(figsize=(11,5))
  ax=fig.add_subplot(1,1,1,projection=projection)
  ax.set_extent(bbox,projection)
  ax.add_feature(cfea.COASTLINE,lw=.5)
  ax.add_feature(cfea.RIVERS,lw=.5)
  ax.add_feature(cfea.BORDERS, linewidth=0.6, edgecolor='dimgray')
  ax.background_patch.set_facecolor('.9')
  levels=[1,4,8,11,14,17,21,25,29]
  cmap=plt.cm.BrBG
  norm=mplt.colors.BoundaryNorm(levels,cmap.N)
  ddlalo=.25
  pc=ax.contourf(lon,lat,kopi,levels=levels,transform=projection,cmap=cmap,norm=norm,extend='both')
  divider = make_axes_locatable(ax)
  ax_cb = divider.new_horizontal(size=&quot;3%&quot;, pad=0.1, axes_class=plt.Axes)
  fig.colorbar(pc,extend='both', cax=ax_cb)
  fig.add_axes(ax_cb)
  fig.colorbar(pc,extend='both', cax=ax_cb)
  ttitle='Jony'
  ax.set_title(ttitle,loc='left',fontsize=9)
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/CD947.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CD947.jpg" alt="enter image description here" /></a></p>
  <p>However, I would like just to plot a selection of values inside the variable ´Band1´. I thought I could use the following code:</p>
  <pre><code>kopi= (nc.variables['Band1'][:,:])&lt;=3
  </code></pre>
  <p>However it does not work and instead of plotting the area corresponding to the value selection it selected the all map. <a href="https://i.stack.imgur.com/tG3rc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tG3rc.png" alt="enter image description here" /></a></p>
  <p>How could I select and plot a desired range of values inside the variables ´Band1´?</p>