在matplotlib中使用imshow绘制netcdf时如何增加对比度? [英] How to increase contrast when plotting a netcdf using imshow in matplotlib?
问题描述
使用imshow绘制数据(来自netcdf)时,是否有增加对比度的方法?在ArcMap中,可以使用
我想要的东西("2.5标准偏差范围"):
尝试 imshow
函数的两个参数:
plt.imshow(mydata, cmap = 'YlGn, 插值 = 'sinc', vmin = 0, vmax = 0.1)
文档:
https://matplotlib.org/gallery/images_contours_and_fields/interpolation_methods.html https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html
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
这篇关于在matplotlib中使用imshow绘制netcdf时如何增加对比度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!