我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用matplotlib.colors.NoNorm()。
def _locate(self, x): ''' Given a set of color data values, return their corresponding colorbar data coordinates. ''' if isinstance(self.norm, (colors.NoNorm, colors.BoundaryNorm)): b = self._boundaries xn = x else: # Do calculations using normalized coordinates so # as to make the interpolation more accurate. b = self.norm(self._boundaries, clip=False).filled() xn = self.norm(x, clip=False).filled() # The rest is linear interpolation with extrapolation at ends. y = self._y N = len(b) ii = np.searchsorted(b, xn) i0 = ii - 1 itop = (ii == N) ibot = (ii == 0) i0[itop] -= 1 ii[itop] -= 1 i0[ibot] += 1 ii[ibot] += 1 #db = b[ii] - b[i0] db = np.take(b, ii) - np.take(b, i0) #dy = y[ii] - y[i0] dy = np.take(y, ii) - np.take(y, i0) z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db return z
def _locate(self, x): ''' Given a set of color data values, return their corresponding colorbar data coordinates. ''' if isinstance(self.norm, (colors.NoNorm, colors.BoundaryNorm)): b = self._boundaries xn = x else: # Do calculations using normalized coordinates so # as to make the interpolation more accurate. b = self.norm(self._boundaries, clip=False).filled() xn = self.norm(x, clip=False).filled() # The rest is linear interpolation with extrapolation at ends. ii = np.searchsorted(b, xn) i0 = ii - 1 itop = (ii == len(b)) ibot = (ii == 0) i0[itop] -= 1 ii[itop] -= 1 i0[ibot] += 1 ii[ibot] += 1 db = np.take(b, ii) - np.take(b, i0) y = self._y dy = np.take(y, ii) - np.take(y, i0) z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db return z
def _ticker(self): ''' Return two sequences: ticks (colorbar data locations) and ticklabels (strings). ''' locator = self.locator formatter = self.formatter if locator is None: if self.boundaries is None: if isinstance(self.norm, colors.NoNorm): nv = len(self._values) base = 1 + int(nv / 10) locator = ticker.IndexLocator(base=base, offset=0) elif isinstance(self.norm, colors.BoundaryNorm): b = self.norm.boundaries locator = ticker.FixedLocator(b, nbins=10) elif isinstance(self.norm, colors.LogNorm): locator = ticker.LogLocator() else: locator = ticker.MaxNLocator() else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if isinstance(self.norm, colors.NoNorm): intv = self._values[0], self._values[-1] else: intv = self.vmin, self.vmax locator.create_dummy_axis(minpos=intv[0]) formatter.create_dummy_axis(minpos=intv[0]) locator.set_view_interval(*intv) locator.set_data_interval(*intv) formatter.set_view_interval(*intv) formatter.set_data_interval(*intv) b = np.array(locator()) ticks = self._locate(b) inrange = (ticks > -0.001) & (ticks < 1.001) ticks = ticks[inrange] b = b[inrange] formatter.set_locs(b) ticklabels = [formatter(t, i) for i, t in enumerate(b)] offset_string = formatter.get_offset() return ticks, ticklabels, offset_string
def _ticker(self): ''' Return the sequence of ticks (colorbar data locations), ticklabels (strings), and the corresponding offset string. ''' locator = self.locator formatter = self.formatter if locator is None: if self.boundaries is None: if isinstance(self.norm, colors.NoNorm): nv = len(self._values) base = 1 + int(nv / 10) locator = ticker.IndexLocator(base=base, offset=0) elif isinstance(self.norm, colors.BoundaryNorm): b = self.norm.boundaries locator = ticker.FixedLocator(b, nbins=10) elif isinstance(self.norm, colors.LogNorm): locator = ticker.LogLocator() else: locator = ticker.MaxNLocator() else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b, nbins=10) if isinstance(self.norm, colors.NoNorm): intv = self._values[0], self._values[-1] else: intv = self.vmin, self.vmax locator.create_dummy_axis(minpos=intv[0]) formatter.create_dummy_axis(minpos=intv[0]) locator.set_view_interval(*intv) locator.set_data_interval(*intv) formatter.set_view_interval(*intv) formatter.set_data_interval(*intv) b = np.array(locator()) ticks = self._locate(b) inrange = (ticks > -0.001) & (ticks < 1.001) ticks = ticks[inrange] b = b[inrange] formatter.set_locs(b) ticklabels = [formatter(t, i) for i, t in enumerate(b)] offset_string = formatter.get_offset() return ticks, ticklabels, offset_string
def _plot_zclasses(self): if self.parts is None: parts = [np.ones_like(self.xdata, dtype=bool)] else: parts = self.parts good = np.sum(parts, axis=0, dtype=bool) good *= np.isfinite(self.xdata) good *= np.isfinite(self.ydata) #good *= np.isfinite(self.zdata) # TODO: Sem essa linha, onde não houver classificação será plotado de preto classes = np.unique(self.zdata[good]) self.classes = classes[classes != self.nullclass] n = self.zdata.shape[0] m = len(self.classes) ncc = len(self.classcolors.values()[0]) zdata = np.full((n, ncc), np.nan) for cls in self.classes: zdata[self.zdata == cls] = self.classcolors[cls] zdata[self.zdata == self.nullclass] = self.nullcolor cmap = ListedColormap([self.classcolors[cls] for cls in self.classes]) cmap.set_bad(self.nullcolor) self.zticks = range(m) self.zlim = [-0.5, m - 0.5] norm = NoNorm(*self.zlim) for part in parts: x = self.xdata[part*good] y = self.ydata[part*good] c = zdata[part*good] collection = self.crossplot_ax.scatter(x, y, c=c, cmap=cmap, zorder=-len(x), **self.collectionproperties) self.collections.append(collection) xticks = self.xlocator(np.min(self.xdata[good]), np.max(self.xdata[good])) self.set_xlim([xticks[0], xticks[-1]]) yticks = self.ylocator(np.min(self.ydata[good]), np.max(self.ydata[good])) self.set_ylim([yticks[0], yticks[-1]]) self.colorbar = ColorbarBase(self.colorbar_ax, cmap=cmap, norm=norm, ticks=self.zticks) #self.colorbar_ax.yaxis.set_major_formatter(NullFormatter())