简体   繁体   中英

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

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'):

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM