How to remove grey boundary lines in a map when plotting a netcdf using imshow in matplotlib?

你说的曾经没有我的故事 提交于 2019-12-12 02:19:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!