def __init__(self, *kl, **kwargs): pad = kwargs.pop("pad", 0.0) add_all = kwargs.pop("add_all", True) axes_class = kwargs.pop("axes_class", None) if axes_class is None: axes_class = axislines.Axes ax = axes_class(*kl, **kwargs) divider = make_axes_locatable(ax) pad_size = Size.Fraction(pad, Size.AxesY(ax)) xsize = Size.Fraction((1. - 2. * pad) / 3., Size.AxesX(ax)) ysize = Size.Fraction((1. - 2. * pad) / 3., Size.AxesY(ax)) divider.set_horizontal([Size.AxesX(ax), pad_size, xsize]) divider.set_vertical([ysize, pad_size, ysize, pad_size, ysize]) ax.set_axes_locator(divider.new_locator(0, 0, ny1=-1)) ax_rgb = [] for ny in [4, 2, 0]: ax1 = axes_class(ax.get_figure(), ax.get_position(original=True), sharex=ax, sharey=ax, **kwargs) locator = divider.new_locator(nx=2, ny=ny) ax1.set_axes_locator(locator) for t in ax1.yaxis.get_ticklabels() + ax1.xaxis.get_ticklabels(): t.set_visible(False) if hasattr(ax1, "_axislines"): for axisline in ax1._axislines.values(): axisline.major_ticklabels.set_visible(False) ax_rgb.append(ax1) self.RGB = ax self.R, self.G, self.B = ax_rgb if add_all: fig = ax.get_figure() fig.add_axes(ax) self.add_RGB_to_figure() for ax1 in [self.RGB, self.R, self.G, self.B]: for axisline in ax1._axislines.values(): axisline.line.set_color("w") axisline.major_ticks.set_mec("w")
def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True): """ pad : fraction of the axes height. """ divider = make_axes_locatable(ax) pad_size = Size.Fraction(pad, Size.AxesY(ax)) xsize = Size.Fraction((1. - 2. * pad) / 3., Size.AxesX(ax)) ysize = Size.Fraction((1. - 2. * pad) / 3., Size.AxesY(ax)) divider.set_horizontal([Size.AxesX(ax), pad_size, xsize]) divider.set_vertical([ysize, pad_size, ysize, pad_size, ysize]) ax.set_axes_locator(divider.new_locator(0, 0, ny1=-1)) ax_rgb = [] if axes_class is None: try: axes_class = locatable_axes_factory(ax._axes_class) except AttributeError: axes_class = locatable_axes_factory(type(ax)) for ny in [4, 2, 0]: ax1 = axes_class(ax.get_figure(), ax.get_position(original=True), sharex=ax, sharey=ax) locator = divider.new_locator(nx=2, ny=ny) ax1.set_axes_locator(locator) for t in ax1.yaxis.get_ticklabels() + ax1.xaxis.get_ticklabels(): t.set_visible(False) try: for axis in ax1.axis.values(): axis.major_ticklabels.set_visible(False) except AttributeError: pass ax_rgb.append(ax1) if add_all: fig = ax.get_figure() for ax1 in ax_rgb: fig.add_axes(ax1) return ax_rgb
def _update_locators(self): h = [] v = [] h_ax_pos = [] h_cb_pos = [] if self._colorbar_mode == "single" and self._colorbar_location in ('left', 'bottom'): if self._colorbar_location == "left": #sz = Size.Fraction(Size.AxesX(self.axes_llc), self._nrows) sz = Size.Fraction(self._nrows, Size.AxesX(self.axes_llc)) h.append(Size.from_any(self._colorbar_size, sz)) h.append(Size.from_any(self._colorbar_pad, sz)) locator = self._divider.new_locator(nx=0, ny=0, ny1=-1) elif self._colorbar_location == "bottom": #sz = Size.Fraction(Size.AxesY(self.axes_llc), self._ncols) sz = Size.Fraction(self._ncols, Size.AxesY(self.axes_llc)) v.append(Size.from_any(self._colorbar_size, sz)) v.append(Size.from_any(self._colorbar_pad, sz)) locator = self._divider.new_locator(nx=0, nx1=-1, ny=0) for i in range(self.ngrids): self.cbar_axes[i].set_visible(False) self.cbar_axes[0].set_axes_locator(locator) self.cbar_axes[0].set_visible(True) for col,ax in enumerate(self._column_refax): if h: h.append(self._horiz_pad_size) #Size.Fixed(self._axes_pad)) if ax: sz = Size.AxesX(ax) else: sz = Size.AxesX(self.axes_llc) if (self._colorbar_mode == "each" or (self._colorbar_mode == 'edge' and col == 0)) and self._colorbar_location == "left": h_cb_pos.append(len(h)) h.append(Size.from_any(self._colorbar_size, sz)) h.append(Size.from_any(self._colorbar_pad, sz)) h_ax_pos.append(len(h)) h.append(sz) if (self._colorbar_mode == "each" or (self._colorbar_mode == 'edge' and col == self._ncols - 1)) and self._colorbar_location == "right": h.append(Size.from_any(self._colorbar_pad, sz)) h_cb_pos.append(len(h)) h.append(Size.from_any(self._colorbar_size, sz)) v_ax_pos = [] v_cb_pos = [] for row,ax in enumerate(self._row_refax[::-1]): if v: v.append(self._horiz_pad_size) #Size.Fixed(self._axes_pad)) if ax: sz = Size.AxesY(ax) else: sz = Size.AxesY(self.axes_llc) if (self._colorbar_mode == "each" or (self._colorbar_mode == 'edge' and row == 0)) and self._colorbar_location == "bottom": v_cb_pos.append(len(v)) v.append(Size.from_any(self._colorbar_size, sz)) v.append(Size.from_any(self._colorbar_pad, sz)) v_ax_pos.append(len(v)) v.append(sz) if (self._colorbar_mode == "each" or (self._colorbar_mode == 'edge' and row == self._nrows - 1)) and self._colorbar_location == "top": v.append(Size.from_any(self._colorbar_pad, sz)) v_cb_pos.append(len(v)) v.append(Size.from_any(self._colorbar_size, sz)) for i in range(self.ngrids): col, row = self._get_col_row(i) #locator = self._divider.new_locator(nx=4*col, ny=2*(self._nrows - row - 1)) locator = self._divider.new_locator(nx=h_ax_pos[col], ny=v_ax_pos[self._nrows -1 - row]) self.axes_all[i].set_axes_locator(locator) if self._colorbar_mode == "each": if self._colorbar_location in ("right", "left"): locator = self._divider.new_locator(nx=h_cb_pos[col], ny=v_ax_pos[self._nrows -1 - row]) elif self._colorbar_location in ("top", "bottom"): locator = self._divider.new_locator(nx=h_ax_pos[col], ny=v_cb_pos[self._nrows -1 - row]) self.cbar_axes[i].set_axes_locator(locator) elif self._colorbar_mode == 'edge': if ((self._colorbar_location == 'left' and col == 0) or (self._colorbar_location == 'right' and col == self._ncols-1)): locator = self._divider.new_locator(nx=h_cb_pos[0], ny=v_ax_pos[self._nrows -1 - row]) self.cbar_axes[row].set_axes_locator(locator) elif ((self._colorbar_location == 'bottom' and row == self._nrows - 1) or (self._colorbar_location == 'top' and row == 0)): locator = self._divider.new_locator(nx=h_ax_pos[col], ny=v_cb_pos[0]) self.cbar_axes[col].set_axes_locator(locator) if self._colorbar_mode == "single": if self._colorbar_location == "right": #sz = Size.Fraction(Size.AxesX(self.axes_llc), self._nrows) sz = Size.Fraction(self._nrows, Size.AxesX(self.axes_llc)) h.append(Size.from_any(self._colorbar_pad, sz)) h.append(Size.from_any(self._colorbar_size, sz)) locator = self._divider.new_locator(nx=-2, ny=0, ny1=-1) elif self._colorbar_location == "top": #sz = Size.Fraction(Size.AxesY(self.axes_llc), self._ncols) sz = Size.Fraction(self._ncols, Size.AxesY(self.axes_llc)) v.append(Size.from_any(self._colorbar_pad, sz)) v.append(Size.from_any(self._colorbar_size, sz)) locator = self._divider.new_locator(nx=0, nx1=-1, ny=-2) if self._colorbar_location in ("right", "top"): for i in range(self.ngrids): self.cbar_axes[i].set_visible(False) self.cbar_axes[0].set_axes_locator(locator) self.cbar_axes[0].set_visible(True) elif self._colorbar_mode == "each": for i in range(self.ngrids): self.cbar_axes[i].set_visible(True) elif self._colorbar_mode == "edge": if self._colorbar_location in ('right', 'left'): count = self._nrows else: count = self._ncols for i in range(count): self.cbar_axes[i].set_visible(True) for j in range(i + 1, self.ngrids): self.cbar_axes[j].set_visible(False) else: for i in range(self.ngrids): self.cbar_axes[i].set_visible(False) self.cbar_axes[i].set_position([1., 1., 0.001, 0.001], which="active") self._divider.set_horizontal(h) self._divider.set_vertical(v)
def _update_locators(self): h = [] h_ax_pos = [] h_cb_pos = [] for ax in self._column_refax: if h: h.append(self._horiz_pad_size) #Size.Fixed(self._axes_pad)) h_ax_pos.append(len(h)) if ax: sz = Size.AxesX(ax) else: sz = Size.AxesX(self.axes_llc) h.append(sz) if self._colorbar_mode == "each" and self._colorbar_location == "right": h.append(Size.from_any(self._colorbar_pad, sz)) h_cb_pos.append(len(h)) h.append(Size.from_any(self._colorbar_size, sz)) v = [] v_ax_pos = [] v_cb_pos = [] for ax in self._row_refax[::-1]: if v: v.append(self._horiz_pad_size) #Size.Fixed(self._axes_pad)) v_ax_pos.append(len(v)) if ax: sz = Size.AxesY(ax) else: sz = Size.AxesY(self.axes_llc) v.append(sz) if self._colorbar_mode == "each" and self._colorbar_location == "top": v.append(Size.from_any(self._colorbar_pad, sz)) v_cb_pos.append(len(v)) v.append(Size.from_any(self._colorbar_size, sz)) for i in range(self.ngrids): col, row = self._get_col_row(i) #locator = self._divider.new_locator(nx=4*col, ny=2*(self._nrows - row - 1)) locator = self._divider.new_locator(nx=h_ax_pos[col], ny=v_ax_pos[self._nrows - 1 - row]) self.axes_all[i].set_axes_locator(locator) if self._colorbar_mode == "each": if self._colorbar_location == "right": locator = self._divider.new_locator( nx=h_cb_pos[col], ny=v_ax_pos[self._nrows - 1 - row]) elif self._colorbar_location == "top": locator = self._divider.new_locator( nx=h_ax_pos[col], ny=v_cb_pos[self._nrows - 1 - row]) self.cbar_axes[i].set_axes_locator(locator) if self._colorbar_mode == "single": if self._colorbar_location == "right": #sz = Size.Fraction(Size.AxesX(self.axes_llc), self._nrows) sz = Size.Fraction(self._nrows, Size.AxesX(self.axes_llc)) h.append(Size.from_any(self._colorbar_pad, sz)) h.append(Size.from_any(self._colorbar_size, sz)) locator = self._divider.new_locator(nx=-2, ny=0, ny1=-1) elif self._colorbar_location == "top": #sz = Size.Fraction(Size.AxesY(self.axes_llc), self._ncols) sz = Size.Fraction(self._ncols, Size.AxesY(self.axes_llc)) v.append(Size.from_any(self._colorbar_pad, sz)) v.append(Size.from_any(self._colorbar_size, sz)) locator = self._divider.new_locator(nx=0, nx1=-1, ny=-2) for i in range(self.ngrids): self.cbar_axes[i].set_visible(False) self.cbar_axes[0].set_axes_locator(locator) self.cbar_axes[0].set_visible(True) elif self._colorbar_mode == "each": for i in range(self.ngrids): self.cbar_axes[i].set_visible(True) else: for i in range(self.ngrids): self.cbar_axes[i].set_visible(False) self.cbar_axes[i].set_position([1., 1., 0.001, 0.001], which="active") self._divider.set_horizontal(h) self._divider.set_vertical(v)