How to increase contrast when plotting a netcdf using imshow in matplotlib?

余生长醉 提交于 2019-12-11 12:59:09

问题


Is there a way to increase contrast when plotting data (from a netcdf) using imshow? In ArcMap this can be done using the 'stretch' function but I would like a solution using matplotlib.

from netCDF4 import 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

Current output:

What I would like (a '2.5 standard deviation stretch'):


回答1:


Try two arguments of the imshow function:

plt.imshow(mydata, cmap = 'YlGn, interpolation = 'sinc', vmin = 0, vmax = 0.1)

The documentations:

https://matplotlib.org/gallery/images_contours_and_fields/interpolation_methods.html https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html



来源:https://stackoverflow.com/questions/38340731/how-to-increase-contrast-when-plotting-a-netcdf-using-imshow-in-matplotlib

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