⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image_masked.py

📁 非原创。很好的python例子
💻 PY
字号:
#!/usr/bin/env python'''imshow with masked array input and out-of-range colors.'''from pylab import *import matplotlib.numerix.ma as maimport matplotlib.colors as colorsdelta = 0.025x = y = arange(-3.0, 3.0, delta)X, Y = meshgrid(x, y)Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)Z = 10 * (Z2-Z1)  # difference of Gaussians# Set up a colormap:palette = cm.graypalette.set_over('r', 1.0)palette.set_under('g', 1.0)palette.set_bad('b', 1.0)# Alternatively, we could use# palette.set_bad(alpha = 0.0)# to make the bad region transparent.  This is the default.# If you comment out all the palette.set* lines, you will see# all the defaults; under and over will be colored with the# first and last colors in the palette, respectively.Zm = ma.masked_where(Z > 1.2, Z)# By setting vmin and vmax in the norm, we establish the# range to which the regular palette color scale is applied.# Anything above that range is colored based on palette.set_over, etc.im = imshow(Zm, interpolation='bilinear',    cmap=palette,    norm = colors.normalize(vmin = -1.0, vmax = 1.0, clip = False),    origin='lower', extent=[-3,3,-3,3])title('Green=low, Red=high, Blue=bad')# colorbar(im) # colorbar does not yet show the under and over colors.show()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -