예제 #1
0
 def __init__(self, axes):
     """
     :param axes: axes
     """
     self._axes = axes
     self._xref = Size.AxesX(axes)
     self._yref = Size.AxesY(axes)
     Divider.__init__(self, fig=axes.get_figure(), pos=None,
                      horizontal=[self._xref], vertical=[self._yref],
                      aspect=None, anchor="C")
예제 #2
0
    def __init__(self, axes, xref=None, yref=None):
        """
        :param axes: axes
        """
        self._axes = axes
        if xref==None:
            self._xref = Size.AxesX(axes)
        else:
            self._xref = xref
        if yref==None:
            self._yref = Size.AxesY(axes)
        else:
            self._yref = yref

        Divider.__init__(self, fig=axes.get_figure(), pos=None,
                         horizontal=[self._xref], vertical=[self._yref],
                         aspect=None, anchor="C")
예제 #3
0
def demo_locatable_axes():
    import matplotlib.pyplot as plt

    fig1 = plt.figure(1, (6, 6))
    fig1.clf()

    ## PLOT 1
    # simple image & colorbar
    ax = fig1.add_subplot(2, 2, 1)

    Z, extent = get_demo_image()

    im = ax.imshow(Z, extent=extent, interpolation="nearest")
    cb = plt.colorbar(im)
    plt.setp(cb.ax.get_yticklabels(), visible=False)

    ## PLOT 2
    # image and colorbar whose location is adjusted in the drawing time.
    # a hard way

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

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

    # axes for coloarbar
    ax_cb = LocatableAxes(fig1, 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))

    fig1.add_axes(ax)
    fig1.add_axes(ax_cb)

    ax_cb.yaxis.set_ticks_position("right")

    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)

    plt.draw()
    #plt.colorbar(im, cax=ax_cb)

    ## PLOT 3
    # image and colorbar whose location is adjusted in the drawing time.
    # a easy way

    ax = fig1.add_subplot(2, 2, 3)
    divider = make_axes_locatable(ax)

    ax_cb = divider.new_horizontal(size="5%", pad=0.05)
    fig1.add_axes(ax_cb)

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

    ## PLOT 4
    # two images side by sied with fixed padding.

    ax = fig1.add_subplot(2, 2, 4)
    divider = make_axes_locatable(ax)

    ax2 = divider.new_horizontal(size="100%", pad=0.05)
    fig1.add_axes(ax2)

    ax.imshow(Z, extent=extent, interpolation="nearest")
    ax2.imshow(Z, extent=extent, interpolation="nearest")
    plt.setp(ax2.get_yticklabels(), visible=False)
    plt.draw()
    plt.show()