def __init__(self, ax, cview_args={}, display_args={}, colormap=[]):

        cview_ax = Axes(ax.get_figure(), ax.get_position(original=True))
        cmap_ax = Axes(ax.get_figure(), ax.get_position(original=True))

        self.ax = ax
        self.cview = ColorViewer(cview_ax, **cview_args)
        self.colormap = MapDisplay(cmap_ax, self.cview, **display_args)
        for name, color in colormap:
            self.colormap.add_item(name, color)

        divider = make_axes_locatable(ax)
        pad = Size.Fixed(0.1)
        colormap_width = Size.Fraction(0.29, Size.AxesX(ax))
        cview_width = Size.Fraction(0.7, Size.AxesX(ax))
        divider.set_horizontal([colormap_width, pad, cview_width])

        cmap_ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
        ax.figure.add_axes(cmap_ax)

        cview_ax.set_axes_locator(divider.new_locator(nx=2, ny=0))
        ax.figure.add_axes(cview_ax)

        ax.tick_params(left=False,
                       bottom=False,
                       labelleft=False,
                       labelbottom=False)
        ax.set_axis_off()
示例#2
0
def demo_locatable_axes_hard(fig):
    from mpl_toolkits.axes_grid1 import SubplotDivider, Size
    from mpl_toolkits.axes_grid1.mpl_axes import Axes
    divider = SubplotDivider(fig, 2, 2, 2, aspect=True)

    # axes for image
    ax = Axes(fig, divider.get_position())

    # axes for colorbar
    ax_cb = Axes(fig, divider.get_position())
    h = [
        Size.AxesX(ax),  # main axes
        Size.Fixed(0.05),  # padding, 0.1 inch
        Size.Fixed(0.2),  # colorbar, 0.3 inch
    ]
    v = [Size.AxesY(ax)]
    divider.set_horizontal(h)
    divider.set_vertical(v)
    ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
    ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0))
    fig.add_axes(ax)
    fig.add_axes(ax_cb)
    ax_cb.axis["left"].toggle(all=False)
    ax_cb.axis["right"].toggle(ticks=True)
    Z, extent = get_demo_image()
    im = ax.imshow(Z, extent=extent, interpolation="nearest")
    plt.colorbar(im, cax=ax_cb)
    plt.setp(ax_cb.get_yticklabels(), visible=False)
示例#3
0
 def clearplot(self):
     utils.trace('in')
     if self._plot is not None:
         if self._plot[0] == 'surface':
             self._plot[1].remove()
             figure = self._plot[3]
             if len(figure.axes) > 1:
                 figure.delaxes(figure.axes[1])
             ax = self._earthplot._axes
             cbax = self._earthplot._clrbar_axes
             divider = make_axes_locatable(ax)
             divider.set_horizontal(
                 [Size.AxesX(ax),
                  Size.Fixed(0),
                  Size.Fixed(0)])
         elif self._plot[0] == 'contour':
             for element in self._plot[1].collections:
                 try:
                     element.remove()
                 except ValueError:
                     print(element)
             if len(self._plot) > 2:
                 try:
                     self._plot[2][0].remove()
                 except TypeError:
                     print("None element cannot be removed")
                 try:
                     self._plot[3].remove()
                 except AttributeError:
                     print("None element have no attribute remove")
                 for element in self._plot[4]:
                     element.remove()
     self._plot = None
     utils.trace('out')
示例#4
0
def addColorbar(mappable, ax):
    """ Append colorbar to axes

    Parameters
    ----------
    mappable :
        a mappable object
    ax :
        an axes object

    Returns
    -------
    cbax :
        colorbar axes object

    Notes
    -----
    This is mostly useful for axes created with :func:`curvedEarthAxes`.

    written by Sebastien, 2013-04

    """
    from mpl_toolkits.axes_grid1 import SubplotDivider, LocatableAxes, Size
    import matplotlib.pyplot as plt

    fig1 = ax.get_figure()
    divider = SubplotDivider(fig1, *ax.get_geometry(), aspect=True)

    # axes for colorbar
    cbax = LocatableAxes(fig1, divider.get_position())

    h = [
        Size.AxesX(ax),  # main axes
        Size.Fixed(0.1),  # padding
        Size.Fixed(0.2)
    ]  # colorbar
    v = [Size.AxesY(ax)]

    _ = divider.set_horizontal(h)
    _ = divider.set_vertical(v)

    _ = ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
    _ = cbax.set_axes_locator(divider.new_locator(nx=2, ny=0))

    _ = fig1.add_axes(cbax)

    _ = cbax.axis["left"].toggle(all=False)
    _ = cbax.axis["top"].toggle(all=False)
    _ = cbax.axis["bottom"].toggle(all=False)
    _ = cbax.axis["right"].toggle(ticklabels=True, label=True)

    _ = plt.colorbar(mappable, cax=cbax)

    return cbax
示例#5
0
def plot_heatmap(fig2, Z):
    from mpl_toolkits.axes_grid1 \
     import SubplotDivider, LocatableAxes, Size

    Z = np.flipud(Z)

    divider = SubplotDivider(fig2, 1, 1, 1, aspect=True)

    # axes for image
    ax = LocatableAxes(fig2, divider.get_position())

    # axes for colorbar
    ax_cb = LocatableAxes(fig2, divider.get_position())

    h = [
        Size.AxesX(ax),  # main axes
        Size.Fixed(0.05),  # padding, 0.1 inch
        Size.Fixed(0.2),  # colorbar, 0.3 inch
    ]

    v = [Size.AxesY(ax)]

    divider.set_horizontal(h)
    divider.set_vertical(v)

    ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
    ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0))

    fig2.add_axes(ax)
    fig2.add_axes(ax_cb)

    ax_cb.axis["left"].toggle(all=False)
    ax_cb.axis["right"].toggle(ticks=True)

    im = ax.imshow(Z,
                   cmap=cm.coolwarm,
                   extent=(0, 1, 0, 1),
                   interpolation="nearest")
    plt.colorbar(im, cax=ax_cb)
    plt.setp(ax_cb.get_yticklabels(), visible=False)

    mngr = plt.get_current_fig_manager()
    geom = mngr.window.geometry()
    x, y, dx, dy = geom.getRect()
    mngr.window.setGeometry(dx + 200, 100, dx, dy)
示例#6
0
def plot2dHeatMap(fig, x, y, z):
    '''z is a 2d grid; x and y are implicit linspaces'''

    from mpl_toolkits.axes_grid1 \
     import SubplotDivider, LocatableAxes, Size

    z = np.flipud(z)

    divider = SubplotDivider(fig, 1, 1, 1, aspect=True)

    # axes for image
    ax = LocatableAxes(fig, divider.get_position())

    # axes for colorbar
    ax_cb = LocatableAxes(fig, divider.get_position())

    h = [
        Size.AxesX(ax),  # main axes
        Size.Fixed(0.05),  # padding, 0.1 inch
        Size.Fixed(0.2),  # colorbar, 0.3 inch
    ]

    v = [Size.AxesY(ax)]

    divider.set_horizontal(h)
    divider.set_vertical(v)

    ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
    ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0))

    fig.add_axes(ax)
    fig.add_axes(ax_cb)

    ax_cb.axis["left"].toggle(all=False)
    ax_cb.axis["right"].toggle(ticks=True)

    im = ax.imshow(z,
                   cmap=cm.coolwarm,
                   extent=(0, 1, 0, 1),
                   interpolation="nearest")
    plt.colorbar(im, cax=ax_cb)
    plt.setp(ax_cb.get_yticklabels(), visible=False)

    return ax
示例#7
0
def add_cbar(mappable, ax):
    """ 
    Append colorbar to axes
    Copied from DaViTPy: https://github.com/vtsuperdarn/davitpy/blob/1b578ea2491888e3d97d6e0a8bc6d8cc7c9211fb/davitpy/utils/plotUtils.py#L674
    """
    from mpl_toolkits.axes_grid1 import SubplotDivider, Size
    from mpl_toolkits.axes_grid1.mpl_axes import Axes
    import matplotlib.pyplot as plt

    fig1 = ax.get_figure()
    divider = SubplotDivider(fig1, *ax.get_geometry(), aspect=True)

    # axes for colorbar
    cbax = Axes(fig1, divider.get_position())

    h = [
        Size.AxesX(ax),  # main axes
        Size.Fixed(0.1),  # padding
        Size.Fixed(0.2)
    ]  # colorbar
    v = [Size.AxesY(ax)]

    _ = divider.set_horizontal(h)
    _ = divider.set_vertical(v)

    _ = ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
    _ = cbax.set_axes_locator(divider.new_locator(nx=2, ny=0))

    _ = fig1.add_axes(cbax)

    _ = cbax.axis["left"].toggle(all=False)
    _ = cbax.axis["top"].toggle(all=False)
    _ = cbax.axis["bottom"].toggle(all=False)
    _ = cbax.axis["right"].toggle(ticklabels=True, label=True)

    _ = plt.colorbar(mappable, cax=cbax)

    return cbax
示例#8
0
def demo_locatable_axes_hard(fig):

    from mpl_toolkits.axes_grid1 import SubplotDivider, Size
    from mpl_toolkits.axes_grid1.mpl_axes import Axes

    divider = SubplotDivider(fig, 2, 2, 2, aspect=True)

    # axes for image
    ax = fig.add_axes(divider.get_position(), axes_class=Axes)

    # axes for colorbar
    # (the label prevents Axes.add_axes from incorrectly believing that the two
    # axes are the same)
    ax_cb = fig.add_axes(divider.get_position(), axes_class=Axes, label="cb")

    h = [
        Size.AxesX(ax),  # main axes
        Size.Fixed(0.05),  # padding, 0.1 inch
        Size.Fixed(0.2),  # colorbar, 0.3 inch
    ]

    v = [Size.AxesY(ax)]

    divider.set_horizontal(h)
    divider.set_vertical(v)

    ax.set_axes_locator(divider.new_locator(nx=0, ny=0))
    ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0))

    ax_cb.axis["left"].toggle(all=False)
    ax_cb.axis["right"].toggle(ticks=True)

    Z, extent = get_demo_image()

    im = ax.imshow(Z, extent=extent)
    plt.colorbar(im, cax=ax_cb)
    ax_cb.yaxis.set_tick_params(labelright=False)
示例#9
0
    def __init__(self, ax, graph, select_opts):

        self._ax = ax

        self._graph = graph
        self._select_opts = select_opts
        if self._select_opts.has_legend:
            self._legend = self._select_opts._legend
        else:
            self._legend = None
        self._vertex_opts = VertexOptions(graph)

        pad = Size.Fixed(0.1)
        graph_width = Size.AxesX(graph.ax)
        self.menu_width = Size.Fraction(0.35, Size.AxesX(graph.ax))
        self.n_rows = 13
        self.cell_height = Size.Fraction(0.97 / 10.0, Size.AxesY(graph.ax))

        divider = make_axes_locatable(ax)
        divider.set_horizontal([graph_width, pad, self.menu_width])

        if self._legend is not None:
            leg_span = self._get_span(self._legend.ax)
            leg_top, leg_bottom = self.n_rows, self.n_rows - leg_span
            menu_layout = [self.cell_height] * leg_span + [pad]
        else:
            leg_top, leg_bottom = None, self.n_rows - leg_span
            menu_layout = []

        sel_opts_span = self._get_span(select_opts.ax)
        sel_opts_top, sel_opts_bottom = leg_bottom - 1, leg_bottom - sel_opts_span - 1
        menu_layout += [self.cell_height] * sel_opts_span + [pad]

        vx_opts_span = self._get_span(self._vertex_opts.ax)
        vx_opts_top, vx_opts_bottom = sel_opts_bottom - 1, sel_opts_bottom - vx_opts_span - 1
        menu_layout += [self.cell_height] * vx_opts_span + [pad]

        # Placeholder for unused space
        menu_layout += [self.cell_height] * (vx_opts_bottom - 1)

        divider.set_vertical([c for c in reversed(menu_layout)])
        self.divider = divider

        graph.ax.set_axes_locator(divider.new_locator(nx=0, ny=0, ny1=-1))
        ax.figure.add_axes(graph.ax)

        self._legend.ax.set_axes_locator(
            divider.new_locator(nx=2, ny=leg_bottom, ny1=leg_top))
        ax.figure.add_axes(self._legend.ax)

        select_opts.ax.set_axes_locator(
            divider.new_locator(nx=2, ny=sel_opts_bottom, ny1=sel_opts_top))
        ax.figure.add_axes(select_opts.ax)

        self._vertex_opts.ax.set_axes_locator(
            divider.new_locator(nx=2, ny=vx_opts_bottom, ny1=vx_opts_top))
        ax.figure.add_axes(self._vertex_opts.ax)

        ax.set_axes_locator(
            divider.new_locator(nx=2, ny=0, ny1=vx_opts_bottom - 1))
        ax.tick_params(left=False,
                       labelleft=False,
                       bottom=False,
                       labelbottom=False)