问题
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