本文介绍了在matplotlib中使用imshow绘制netcdf时,如何删除地图中的灰色边界线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以删除下图中的灰色边界线?我正在尝试使用 matplotlib 绘制netcdf.

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

我认为灰色值是缺少值/没有数据的结果.

I think the grey values are a result of missing values/no data.

推荐答案

这些灰色边界是 imshow 中的插值伪像.要摆脱它们,请执行以下操作:

Those gray boundaries are an interpolation artifact from imshow. To get rid of them, do:

imgplot = plt.imshow(mydata, cmap = 'YlGn', interpolation='none')

或通过 Basemap 进行绘制并显式控制绘图,如此示例.

Or plot through Basemap and control drawing explicitly, as in this example.

这篇关于在matplotlib中使用imshow绘制netcdf时,如何删除地图中的灰色边界线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 20:18