问题
Is it possible to remove the grey boundary lines around the in following map? I am trying to plotting a netcdf using matplotlib
.
from netCDF4 import Dataset # clarify use of Dataset
import matplotlib.pylab as plt
fnc = Dataset(ncfile, 'r')
lat = fnc.variables['latitude'][:]
lon = fnc.variables['longitude'][:]
level = fnc.variables['level'][:]
mydata = fnc.variables['Data'][0, 0, :, :]
plt.figure(figsize = (8, 4))
imgplot = plt.imshow(mydata, cmap = 'YlGn')
plt.colorbar()
plt.show
Edit: I think the grey values are a result of missing values/no data.
回答1:
Those gray boundaries are an interpolation artifact from imshow
. To get rid of them, do:
imgplot = plt.imshow(mydata, cmap = 'YlGn', interpolation='none')
Or plot through Basemap
and control drawing explicitly, as in this example.
来源:https://stackoverflow.com/questions/38338177/how-to-remove-grey-boundary-lines-in-a-map-when-plotting-a-netcdf-using-imshow-i