def make_path(d, style): items = [] for c in d.split(): if c.upper() in codemap: items.append(c) else: x, y = (float(v) for v in c.split(",")) items.append((x, y)) codes = [] vertices = [] i = 0 lx, ly = 0, 0 last_code = "M" while i < len(items): code = items[i] if not isinstance(code, str): code = last_code else: i += 1 ucode = code.upper() if code.isupper(): relative = False else: relative = True if ucode in ("M", "L"): x, y = items[i] i += 1 if relative: x += lx y += ly codes.append(codemap[ucode]) vertices.append((x, y)) lx, ly = x, y if ucode == "C": if not relative: points = items[i:i + 3] else: points = [(_x + lx, _y + ly) for _x, _y in items[i:i + 3]] codes.extend([codemap[ucode]] * 3) vertices.extend(points) lx, ly = points[-1] i += 3 if ucode == "Z": break last_code = code codes[0] = Path.MOVETO patch = PathPatch(Path(vertices, codes)) patch.set_linewidth(get_number(style.get("stroke-width", "1px"))) fill = style.get("fill", "none") if fill == "none": patch.set_fill(None) else: patch.set_facecolor(fill) edge = style.get("stroke", "none") patch.set_edgecolor(edge) return patch
def make_path(d, style): items = [] for c in d.split(): if c.upper() in codemap: items.append(c) else: x, y = (float(v) for v in c.split(",")) items.append((x, y)) codes = [] vertices = [] i = 0 lx, ly = 0, 0 last_code = "M" while i < len(items): code = items[i] if not isinstance(code, str): code = last_code else: i += 1 ucode = code.upper() if code.isupper(): relative = False else: relative = True if ucode in ("M", "L"): x, y = items[i] i += 1 if relative: x += lx y += ly codes.append(codemap[ucode]) vertices.append((x, y)) lx, ly = x, y if ucode == "C": if not relative: points = items[i:i+3] else: points = [(_x + lx, _y + ly) for _x, _y in items[i:i+3]] codes.extend([codemap[ucode]]*3) vertices.extend(points) lx, ly = points[-1] i += 3 if ucode == "Z": break last_code = code codes[0] = Path.MOVETO patch = PathPatch( Path(vertices, codes) ) patch.set_linewidth( get_number(style.get("stroke-width", "1px") ) ) fill = style.get("fill", "none") if fill == "none": patch.set_fill( None ) else: patch.set_facecolor( fill ) edge = style.get("stroke", "none") patch.set_edgecolor(edge) return patch
def GenWedge(ofs, rx, ry, facecolor='r', label='', alpha=0.3): codes, verts = [], [] amin = 0 ox, oy = ofs if ox == 0 and oy == 0: amax = np.pi * 2 ngoes = 1 elif ox == 0: amax = np.pi ngoes = 2 else: amax = np.pi / 2 ngoes = 4 phi = np.linspace(amin, amax, 100) for g in range(ngoes): if g == 0: cofs = ofs elif g == 1: if (ngoes == 2): cofs = [0, -ofs[1]] else: cofs = [-ofs[0], ofs[1]] elif g == 2: cofs = [-ofs[0], -ofs[1]] elif g == 3: cofs = [ofs[0], -ofs[1]] codes.append(Path.MOVETO) if ngoes > 1: verts.append(cofs) else: verts.append([cofs[0] + rx, cofs[1]]) for p in phi: if p == 0: codes.append(Path.LINETO) else: #print dir(Path) codes.append(Path.CURVE4) verts.append([ cofs[0] + rx * cos(p + 2 * np.pi / ngoes * g), cofs[1] + ry * sin(p + 2 * np.pi / ngoes * g) ]) if (ngoes > 1): codes.append(Path.CLOSEPOLY) verts.append(ofs) w = PathPatch(Path(verts, codes), label=label) w.set_alpha(alpha) w.set_facecolor(facecolor) w.set_linewidth(0.0) lhandles.append(w) return w
def _render_on_subplot(self, subplot): """ Render this Bezier path in a subplot. This is the key function that defines how this Bezier path graphics primitive is rendered in matplotlib's library. TESTS:: sage: bezier_path([[(0,1),(.5,0),(1,1)]]) Graphics object consisting of 1 graphics primitive :: sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]]) Graphics object consisting of 1 graphics primitive """ from matplotlib.patches import PathPatch from matplotlib.path import Path from sage.plot.misc import get_matplotlib_linestyle options = dict(self.options()) del options['alpha'] del options['thickness'] del options['rgbcolor'] del options['zorder'] del options['fill'] del options['linestyle'] bpath = Path(self.vertices, self.codes) bpatch = PathPatch(bpath, **options) options = self.options() bpatch.set_linewidth(float(options['thickness'])) bpatch.set_fill(options['fill']) bpatch.set_zorder(options['zorder']) a = float(options['alpha']) bpatch.set_alpha(a) c = to_mpl_color(options['rgbcolor']) bpatch.set_edgecolor(c) bpatch.set_facecolor(c) bpatch.set_linestyle( get_matplotlib_linestyle(options['linestyle'], return_type='long')) subplot.add_patch(bpatch)
def _render_on_subplot(self, subplot): """ Render this Bezier path in a subplot. This is the key function that defines how this Bezier path graphics primitive is rendered in matplotlib's library. TESTS:: sage: bezier_path([[(0,1),(.5,0),(1,1)]]) Graphics object consisting of 1 graphics primitive :: sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]]) Graphics object consisting of 1 graphics primitive """ from matplotlib.patches import PathPatch from matplotlib.path import Path from sage.plot.misc import get_matplotlib_linestyle options = dict(self.options()) del options['alpha'] del options['thickness'] del options['rgbcolor'] del options['zorder'] del options['fill'] del options['linestyle'] bpath = Path(self.vertices, self.codes) bpatch = PathPatch(bpath, **options) options = self.options() bpatch.set_linewidth(float(options['thickness'])) bpatch.set_fill(options['fill']) bpatch.set_zorder(options['zorder']) a = float(options['alpha']) bpatch.set_alpha(a) c = to_mpl_color(options['rgbcolor']) bpatch.set_edgecolor(c) bpatch.set_facecolor(c) bpatch.set_linestyle(get_matplotlib_linestyle(options['linestyle'], return_type='long')) subplot.add_patch(bpatch)
class ColorbarBase(cm.ScalarMappable): """ Draw a colorbar in an existing axes. This is a base CustomClass for the :CustomClass:`Colorbar` CustomClass, which is the basis for the :func:`~matplotlib.pyplot.colorbar` method and pyplot function. It is also useful by itself for showing a colormap. If the *cmap* kwarg is given but *boundaries* and *values* are left as None, then the colormap will be displayed on a 0-1 scale. To show the under- and over-value colors, specify the *norm* as:: colors.Normalize(clip=False) To show the colors versus index instead of on the 0-1 scale, use:: norm=colors.NoNorm. Useful attributes: :attr:`ax` the Axes instance in which the colorbar is drawn :attr:`lines` a LineCollection if lines were drawn, otherwise None :attr:`dividers` a LineCollection if *drawedges* is True, otherwise None Useful public methods are :meth:`set_label` and :meth:`add_lines`. """ def __init__( self, ax, cmap=None, norm=None, alpha=1.0, values=None, boundaries=None, orientation='vertical', extend='neither', spacing='uniform', # uniform or proportional ticks=None, format=None, drawedges=False, filled=True, ): self.ax = ax if cmap is None: cmap = cm.get_cmap() if norm is None: norm = colors.Normalize() self.alpha = alpha cm.ScalarMappable.__init__(self, cmap=cmap, norm=norm) self.values = values self.boundaries = boundaries self.extend = extend self.spacing = spacing self.orientation = orientation self.drawedges = drawedges self.filled = filled # artists self.solids = None self.lines = None self.dividers = None self.extension_patch1 = None self.extension_patch2 = None if orientation == "vertical": self.cbar_axis = self.ax.yaxis else: self.cbar_axis = self.ax.xaxis if format is None: if isinstance(self.norm, colors.LogNorm): # change both axis for proper aspect self.ax.set_xscale("log") self.ax.set_yscale("log") self.cbar_axis.set_minor_locator(ticker.NullLocator()) formatter = ticker.LogFormatter() else: formatter = None elif isinstance(format, str): formatter = ticker.FormatStrFormatter(format) else: formatter = format # Assume it is a Formatter if formatter is None: formatter = self.cbar_axis.get_major_formatter() else: self.cbar_axis.set_major_formatter(formatter) if np.iterable(ticks): self.cbar_axis.set_ticks(ticks) elif ticks is not None: self.cbar_axis.set_major_locator(ticks) else: self._select_locator() self._config_axes() self.update_artists() self.set_label_text('') def _get_colorbar_limits(self): """ initial limits for colorbar range. The returned min, max values will be used to create colorbar solid(?) and etc. """ if self.boundaries is not None: C = self.boundaries if self.extend in ["min", "both"]: C = C[1:] if self.extend in ["max", "both"]: C = C[:-1] return min(C), max(C) else: return self.get_clim() def _config_axes(self): """ Adjust the properties of the axes to be adequate for colorbar display. """ ax = self.ax axes_locator = CbarAxesLocator(ax.get_axes_locator(), extend=self.extend, orientation=self.orientation) ax.set_axes_locator(axes_locator) # override the get_data_ratio for the aspect works. def _f(): return 1. ax.get_data_ratio = _f ax.get_data_ratio_log = _f ax.set_frame_on(True) ax.set_navigate(False) self.ax.set_autoscalex_on(False) self.ax.set_autoscaley_on(False) if self.orientation == 'horizontal': ax.xaxis.set_label_position('bottom') ax.set_yticks([]) else: ax.set_xticks([]) ax.yaxis.set_label_position('right') ax.yaxis.set_ticks_position('right') def update_artists(self): """ Update the colorbar associated artists, *filled* and *ends*. Note that *lines* are not updated. This needs to be called whenever clim of associated image changes. """ self._process_values() self._add_ends() X, Y = self._mesh() if self.filled: C = self._values[:, np.newaxis] self._add_solids(X, Y, C) ax = self.ax vmin, vmax = self._get_colorbar_limits() if self.orientation == 'horizontal': ax.set_ylim(1, 2) ax.set_xlim(vmin, vmax) else: ax.set_xlim(1, 2) ax.set_ylim(vmin, vmax) def _add_ends(self): """ Create patches from extended ends and add them to the axes. """ del self.extension_patch1 del self.extension_patch2 path1, path2 = self.ax.get_axes_locator().get_path_ends() fc = mpl.rcParams['axes.facecolor'] ec = mpl.rcParams['axes.edgecolor'] linewidths = 0.5 * mpl.rcParams['axes.linewidth'] self.extension_patch1 = PathPatch(path1, fc=fc, ec=ec, lw=linewidths, zorder=2., transform=self.ax.transAxes, clip_on=False) self.extension_patch2 = PathPatch(path2, fc=fc, ec=ec, lw=linewidths, zorder=2., transform=self.ax.transAxes, clip_on=False) self.ax.add_artist(self.extension_patch1) self.ax.add_artist(self.extension_patch2) def _set_label_text(self): """Set the colorbar label.""" self.cbar_axis.set_label_text(self._label, **self._labelkw) def set_label_text(self, label, **kw): """Label the long axis of the colorbar.""" self._label = label self._labelkw = kw self._set_label_text() def _edges(self, X, Y): """Return the separator line segments; helper for _add_solids.""" N = X.shape[0] # Using the non-array form of these line segments is much # simpler than making them into arrays. if self.orientation == 'vertical': return [list(zip(X[i], Y[i])) for i in range(1, N - 1)] else: return [list(zip(Y[i], X[i])) for i in range(1, N - 1)] def _add_solids(self, X, Y, C): """ Draw the colors using :meth:`~matplotlib.axes.Axes.pcolormesh`; optionally add separators. """ ## Change to pcolorfast after fixing bugs in some backends... if self.extend in ["min", "both"]: cc = self.to_rgba([C[0][0]]) self.extension_patch1.set_facecolor(cc[0]) X, Y, C = X[1:], Y[1:], C[1:] if self.extend in ["max", "both"]: cc = self.to_rgba([C[-1][0]]) self.extension_patch2.set_facecolor(cc[0]) X, Y, C = X[:-1], Y[:-1], C[:-1] if self.orientation == 'vertical': args = (X, Y, C) else: args = (np.transpose(Y), np.transpose(X), np.transpose(C)) del self.solids del self.dividers col = self.ax.pcolormesh(*args, cmap=self.cmap, norm=self.norm, shading='flat', alpha=self.alpha) self.solids = col if self.drawedges: self.dividers = collections.LineCollection( self._edges(X, Y), colors=(mpl.rcParams['axes.edgecolor'], ), linewidths=(0.5 * mpl.rcParams['axes.linewidth'], ), ) self.ax.add_collection(self.dividers) else: self.dividers = None def add_lines(self, levels, colors, linewidths): """Draw lines on the colorbar. It deletes preexisting lines.""" X, Y = np.meshgrid([1, 2], levels) if self.orientation == 'vertical': xy = np.stack([X, Y], axis=-1) else: xy = np.stack([Y, X], axis=-1) col = collections.LineCollection(xy, linewidths=linewidths) self.lines = col col.set_color(colors) self.ax.add_collection(col) def _select_locator(self): """Select a suitable locator.""" 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(nbins=5) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b) self.cbar_axis.set_major_locator(locator) def _process_values(self, b=None): """ Set the :attr:`_boundaries` and :attr:`_values` attributes based on the input boundaries and values. Input boundaries can be *self.boundaries* or the argument *b*. """ if b is None: b = self.boundaries if b is not None: self._boundaries = np.asarray(b, dtype=float) if self.values is None: self._values = (self._boundaries[:-1] + self._boundaries[1:]) / 2 if isinstance(self.norm, colors.NoNorm): self._values = (self._values + 0.00001).astype(np.int16) return self._values = np.array(self.values) return if self.values is not None: self._values = np.array(self.values) if self.boundaries is None: b = np.zeros(len(self.values) + 1) b[1:-1] = 0.5 * (self._values[:-1] - self._values[1:]) b[0] = 2.0 * b[1] - b[2] b[-1] = 2.0 * b[-2] - b[-3] self._boundaries = b return self._boundaries = np.array(self.boundaries) return # Neither boundaries nor values are specified; # make reasonable ones based on cmap and norm. if isinstance(self.norm, colors.NoNorm): self._boundaries = ( self._uniform_y(self.cmap.N + 1) * self.cmap.N - 0.5) self._values = np.arange(self.cmap.N, dtype=np.int16) return elif isinstance(self.norm, colors.BoundaryNorm): self._boundaries = np.array(self.norm.boundaries) self._values = (self._boundaries[:-1] + self._boundaries[1:]) / 2 return else: b = self._uniform_y(self.cmap.N + 1) self._process_values(b) def _uniform_y(self, N): """ Return colorbar data coordinates for *N* uniformly spaced boundaries. """ vmin, vmax = self._get_colorbar_limits() if isinstance(self.norm, colors.LogNorm): y = np.geomspace(vmin, vmax, N) else: y = np.linspace(vmin, vmax, N) return y def _mesh(self): """ Return X,Y, the coordinate arrays for the colorbar pcolormesh. These are suitable for a vertical colorbar; swapping and transposition for a horizontal colorbar are done outside this function. """ x = np.array([1.0, 2.0]) if self.spacing == 'uniform': y = self._uniform_y(len(self._boundaries)) else: y = self._boundaries self._y = y X, Y = np.meshgrid(x, y) return X, Y def set_alpha(self, alpha): """Set the alpha value for transparency.""" self.alpha = alpha
class ColorbarBase(cm.ScalarMappable): ''' Draw a colorbar in an existing axes. This is a base class for the :class:`Colorbar` class, which is the basis for the :func:`~matplotlib.pyplot.colorbar` method and pyplot function. It is also useful by itself for showing a colormap. If the *cmap* kwarg is given but *boundaries* and *values* are left as None, then the colormap will be displayed on a 0-1 scale. To show the under- and over-value colors, specify the *norm* as:: colors.Normalize(clip=False) To show the colors versus index instead of on the 0-1 scale, use:: norm=colors.NoNorm. Useful attributes: :attr:`ax` the Axes instance in which the colorbar is drawn :attr:`lines` a LineCollection if lines were drawn, otherwise None :attr:`dividers` a LineCollection if *drawedges* is True, otherwise None Useful public methods are :meth:`set_label` and :meth:`add_lines`. ''' def __init__(self, ax, cmap=None, norm=None, alpha=1.0, values=None, boundaries=None, orientation='vertical', extend='neither', spacing='uniform', # uniform or proportional ticks=None, format=None, drawedges=False, filled=True, ): self.ax = ax if cmap is None: cmap = cm.get_cmap() if norm is None: norm = colors.Normalize() self.alpha = alpha cm.ScalarMappable.__init__(self, cmap=cmap, norm=norm) self.values = values self.boundaries = boundaries self.extend = extend self.spacing = spacing self.orientation = orientation self.drawedges = drawedges self.filled = filled # artists self.solids = None self.lines = None self.dividers = None self.extension_patch1 = None self.extension_patch2 = None if orientation == "vertical": self.cbar_axis = self.ax.yaxis else: self.cbar_axis = self.ax.xaxis if format is None: if isinstance(self.norm, colors.LogNorm): # change both axis for proper aspect self.ax.set_xscale("log") self.ax.set_yscale("log") self.cbar_axis.set_minor_locator(ticker.NullLocator()) formatter = ticker.LogFormatter() else: formatter = None elif isinstance(format, str): formatter = ticker.FormatStrFormatter(format) else: formatter = format # Assume it is a Formatter if formatter is None: formatter = self.cbar_axis.get_major_formatter() else: self.cbar_axis.set_major_formatter(formatter) if np.iterable(ticks): self.cbar_axis.set_ticks(ticks) elif ticks is not None: self.cbar_axis.set_major_locator(ticks) else: self._select_locator(formatter) self._config_axes() self.update_artists() self.set_label_text('') def _get_colorbar_limits(self): """ initial limits for colorbar range. The returned min, max values will be used to create colorbar solid(?) and etc. """ if self.boundaries is not None: C = self.boundaries if self.extend in ["min", "both"]: C = C[1:] if self.extend in ["max", "both"]: C = C[:-1] return min(C), max(C) else: return self.get_clim() def _config_axes(self): ''' Adjust the properties of the axes to be adequate for colorbar display. ''' ax = self.ax axes_locator = CbarAxesLocator(ax.get_axes_locator(), extend=self.extend, orientation=self.orientation) ax.set_axes_locator(axes_locator) # override the get_data_ratio for the aspect works. def _f(): return 1. ax.get_data_ratio = _f ax.get_data_ratio_log = _f ax.set_frame_on(True) ax.set_navigate(False) self.ax.set_autoscalex_on(False) self.ax.set_autoscaley_on(False) if self.orientation == 'horizontal': ax.xaxis.set_label_position('bottom') ax.set_yticks([]) else: ax.set_xticks([]) ax.yaxis.set_label_position('right') ax.yaxis.set_ticks_position('right') def update_artists(self): """ Update the colorbar associated artists, *filled* and *ends*. Note that *lines* are not updated. This needs to be called whenever clim of associated image changes. """ self._process_values() self._add_ends() X, Y = self._mesh() if self.filled: C = self._values[:, np.newaxis] self._add_solids(X, Y, C) ax = self.ax vmin, vmax = self._get_colorbar_limits() if self.orientation == 'horizontal': ax.set_ylim(1, 2) ax.set_xlim(vmin, vmax) else: ax.set_xlim(1, 2) ax.set_ylim(vmin, vmax) def _add_ends(self): """ Create patches from extended ends and add them to the axes. """ del self.extension_patch1 del self.extension_patch2 path1, path2 = self.ax.get_axes_locator().get_path_ends() fc=mpl.rcParams['axes.facecolor'] ec=mpl.rcParams['axes.edgecolor'] linewidths=0.5*mpl.rcParams['axes.linewidth'] self.extension_patch1 = PathPatch(path1, fc=fc, ec=ec, lw=linewidths, zorder=2., transform=self.ax.transAxes, clip_on=False) self.extension_patch2 = PathPatch(path2, fc=fc, ec=ec, lw=linewidths, zorder=2., transform=self.ax.transAxes, clip_on=False) self.ax.add_artist(self.extension_patch1) self.ax.add_artist(self.extension_patch2) def _set_label_text(self): """ set label. """ self.cbar_axis.set_label_text(self._label, **self._labelkw) def set_label_text(self, label, **kw): ''' Label the long axis of the colorbar ''' self._label = label self._labelkw = kw self._set_label_text() def _edges(self, X, Y): ''' Return the separator line segments; helper for _add_solids. ''' N = X.shape[0] # Using the non-array form of these line segments is much # simpler than making them into arrays. if self.orientation == 'vertical': return [list(zip(X[i], Y[i])) for i in range(1, N-1)] else: return [list(zip(Y[i], X[i])) for i in range(1, N-1)] def _add_solids(self, X, Y, C): ''' Draw the colors using :meth:`~matplotlib.axes.Axes.pcolormesh`; optionally add separators. ''' ## Change to pcolorfast after fixing bugs in some backends... if self.extend in ["min", "both"]: cc = self.to_rgba([C[0][0]]) self.extension_patch1.set_facecolor(cc[0]) X, Y, C = X[1:], Y[1:], C[1:] if self.extend in ["max", "both"]: cc = self.to_rgba([C[-1][0]]) self.extension_patch2.set_facecolor(cc[0]) X, Y, C = X[:-1], Y[:-1], C[:-1] if self.orientation == 'vertical': args = (X, Y, C) else: args = (np.transpose(Y), np.transpose(X), np.transpose(C)) del self.solids del self.dividers col = self.ax.pcolormesh( *args, cmap=self.cmap, norm=self.norm, shading='flat', alpha=self.alpha) self.solids = col if self.drawedges: self.dividers = collections.LineCollection( self._edges(X, Y), colors=(mpl.rcParams['axes.edgecolor'],), linewidths=(0.5*mpl.rcParams['axes.linewidth'],), ) self.ax.add_collection(self.dividers) else: self.dividers = None def add_lines(self, levels, colors, linewidths): ''' Draw lines on the colorbar. It deletes preexisting lines. ''' X, Y = np.meshgrid([1, 2], levels) if self.orientation == 'vertical': xy = np.stack([X, Y], axis=-1) else: xy = np.stack([Y, X], axis=-1) col = collections.LineCollection(xy, linewidths=linewidths) self.lines = col col.set_color(colors) self.ax.add_collection(col) def _select_locator(self, formatter): ''' select a suitable locator ''' 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(nbins=5) else: b = self._boundaries[self._inside] locator = ticker.FixedLocator(b) self.cbar_axis.set_major_locator(locator) def _process_values(self, b=None): ''' Set the :attr:`_boundaries` and :attr:`_values` attributes based on the input boundaries and values. Input boundaries can be *self.boundaries* or the argument *b*. ''' if b is None: b = self.boundaries if b is not None: self._boundaries = np.asarray(b, dtype=float) if self.values is None: self._values = 0.5*(self._boundaries[:-1] + self._boundaries[1:]) if isinstance(self.norm, colors.NoNorm): self._values = (self._values + 0.00001).astype(np.int16) return self._values = np.array(self.values) return if self.values is not None: self._values = np.array(self.values) if self.boundaries is None: b = np.zeros(len(self.values)+1, 'd') b[1:-1] = 0.5*(self._values[:-1] - self._values[1:]) b[0] = 2.0*b[1] - b[2] b[-1] = 2.0*b[-2] - b[-3] self._boundaries = b return self._boundaries = np.array(self.boundaries) return # Neither boundaries nor values are specified; # make reasonable ones based on cmap and norm. if isinstance(self.norm, colors.NoNorm): b = self._uniform_y(self.cmap.N+1) * self.cmap.N - 0.5 v = np.zeros((len(b)-1,), dtype=np.int16) v = np.arange(self.cmap.N, dtype=np.int16) self._boundaries = b self._values = v return elif isinstance(self.norm, colors.BoundaryNorm): b = np.array(self.norm.boundaries) v = np.zeros((len(b)-1,), dtype=float) bi = self.norm.boundaries v = 0.5*(bi[:-1] + bi[1:]) self._boundaries = b self._values = v return else: b = self._uniform_y(self.cmap.N+1) self._process_values(b) def _uniform_y(self, N): ''' Return colorbar data coordinates for *N* uniformly spaced boundaries. ''' vmin, vmax = self._get_colorbar_limits() if isinstance(self.norm, colors.LogNorm): y = np.logspace(np.log10(vmin), np.log10(vmax), N) else: y = np.linspace(vmin, vmax, N) return y def _mesh(self): ''' Return X,Y, the coordinate arrays for the colorbar pcolormesh. These are suitable for a vertical colorbar; swapping and transposition for a horizontal colorbar are done outside this function. ''' x = np.array([1.0, 2.0]) if self.spacing == 'uniform': y = self._uniform_y(len(self._boundaries)) else: y = self._boundaries self._y = y X, Y = np.meshgrid(x, y) return X, Y def set_alpha(self, alpha): """ set alpha value. """ self.alpha = alpha
mult = [mult, -mult] # y axis is inverted offset = mne_corners[-1] - np.array( [mne_clip.get_extents().size[0] / 2., -dims[1]]) - tagline_offset_fudge tag_clip = Path(offset + vert * mult, tag_path.codes) tag_patch = PathPatch(tag_clip, facecolor='k', edgecolor='none', zorder=10) ax.add_patch(tag_patch) yl = ax.get_ylim() yy = np.max([tag_clip.vertices.max(0)[-1], tag_clip.vertices.min(0)[-1]]) ax.set_ylim(np.ceil(yy), yl[-1]) # only save actual image extent plus a bit of padding plt.draw() static_dir = op.join(op.dirname(__file__), '..', 'doc', '_static') assert op.isdir(static_dir) plt.savefig(op.join(static_dir, 'mne_logo.svg'), transparent=True) tag_patch.set_facecolor('w') rect.set_facecolor('0.5') plt.savefig(op.join(static_dir, 'mne_logo_dark.svg'), transparent=True) tag_patch.set_facecolor('k') rect.set_facecolor('w') # modify to make the splash screen data_dir = op.join(op.dirname(__file__), '..', 'mne', 'icons') ax.patches[-1].set_facecolor('w') for coll in list(ax.collections): coll.remove() bounds = np.array( [[mne_path.vertices[:, ii].min(), mne_path.vertices[:, ii].max()] for ii in range(2)]) bounds *= (plot_dims / dims) xy = np.mean(bounds, axis=1) - [100, 0]