def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect):
"""Store output of imshow in image variable"""
if (cbnorm == 'log10'):
norm = matplotlib.colors.LogNorm()
elif (cbnorm == 'linear'):
norm = matplotlib.colors.Normalize()
elif (cbnorm == 'symlog'):
if cblinthresh is None:
cblinthresh = (data.max()-data.min())/10.
norm = matplotlib.colors.SymLogNorm(cblinthresh, vmin=data.min(), vmax=data.max())
extent = [float(e) for e in extent]
# tuple colormaps are from palettable (or brewer2mpl)
if isinstance(cmap, tuple):
cmap = get_brewer_cmap(cmap)
self.image = self.axes.imshow(data.to_ndarray(), origin='lower',
extent=extent, norm=norm, vmin=self.zmin,
aspect=aspect, vmax=self.zmax, cmap=cmap,
interpolation='nearest')
if (cbnorm == 'symlog'):
if LooseVersion(matplotlib.__version__) < LooseVersion("2.0.0"):
formatter_kwargs = {}
else:
formatter_kwargs = dict(linthresh=cblinthresh)
formatter = matplotlib.ticker.LogFormatterMathtext(
**formatter_kwargs)
self.cb = self.figure.colorbar(
self.image, self.cax, format=formatter)
if data.min() >= 0.0:
yticks = [data.min().v] + list(
10**np.arange(np.rint(np.log10(cblinthresh)),
np.ceil(np.log10(data.max())) + 1))
elif data.max() <= 0.0:
yticks = list(
-10**np.arange(
np.floor(np.log10(-data.min())),
np.rint(np.log10(cblinthresh)) - 1, -1)) + \
[data.max().v]
else:
yticks = list(
-10**np.arange(np.floor(np.log10(-data.min())),
np.rint(np.log10(cblinthresh))-1, -1)) + \
[0] + \
list(10**np.arange(np.rint(np.log10(cblinthresh)),
np.ceil(np.log10(data.max()))+1))
self.cb.set_ticks(yticks)
else:
self.cb = self.figure.colorbar(self.image, self.cax)
for which in ['major', 'minor']:
self.cax.tick_params(which=which, axis='y', direction='in')
评论列表
文章目录