コード例 #1
0
def axesRight(fig, rect, ternaryinfo, grid=False, debug=False):
    xname = ternaryinfo.right.name
    vminx, vmaxx = ternaryinfo.right.max, ternaryinfo.right.min
    yname = ternaryinfo.top.name
    vminy, vmaxy = ternaryinfo.top.min, ternaryinfo.top.max

    ox = vminx
    oy = vminy
    sx = float(vmaxx - vminx)
    sy = float(vmaxy - vminy)

    M = plttransforms.Affine2D()
    M += plttransforms.Affine2D().translate(-ox, -oy)
    M += plttransforms.Affine2D().scale(1, sx / sy)
    M += plttransforms.Affine2D().skew_deg(-15, -15)
    M += plttransforms.Affine2D().rotate_deg(15)
    f, fi = transformations(M)

    grid_helper = pltahelper.GridHelperCurveLinear((f, fi))
    ax = plta.Axes(fig, rect, grid_helper=grid_helper, frameon=False)
    ax.axis["top", "right", "left", "bottom"].set_visible(False)

    ax.axis["X"] = ax.new_floating_axis(1, oy)
    ax.axis["X"].label.set_text(xname)
    ax.axis["X"].label.set_color(ternaryinfo.right.color)

    xmax1, ymin1 = f(vminx, vminy)
    xmax1, ymin1 = xmax1[0], ymin1[0]
    xmin1, _ = f(vmaxx, vminy)
    xmin1 = xmin1[0]
    _, ymax1 = f(vminx, vmaxy)
    ymax1 = ymax1[0]
    ax.set_xlim(xmin1, xmax1)
    ax.set_ylim(ymin1, ymax1)

    if debug:
        ax.axis["Y"] = ax.new_floating_axis(0, ox)
        ax.axis["Y"].label.set_text(yname)

        ax.plot(*f([vminx, vmaxx], [vminy, vminy]), marker="o", markersize=10)
        ax.plot(*f([vminx, vminx], [vminy, vmaxy]), marker="+", markersize=10)

    if grid:
        ax.grid(True, axis="x", zorder=0, color=ternaryinfo.right.color)

    return ax
コード例 #2
0
ファイル: zoom.py プロジェクト: kadrlica/cartosky
    def create_axes(self, rect=111):
        """
        Create a special AxisArtist to overlay grid coordinates.

        Much of this taken from the examples here:
        http://matplotlib.org/mpl_toolkits/axes_grid/users/axisartist.html
        """

        # from curved coordinate to rectlinear coordinate.
        def tr(x, y):
            return self(x, y)

        # from rectlinear coordinate to curved coordinate.
        def inv_tr(x, y):
            return self(x, y, inverse=True)

        # Cycle the coordinates
        extreme_finder = angle_helper.ExtremeFinderCycle(20, 20)

        # Find a grid values appropriate for the coordinate.
        # The argument is a approximate number of grid lines.
        grid_locator1 = angle_helper.LocatorD(9, include_last=False)
        # grid_locator1 = angle_helper.LocatorD(8, include_last=False)
        grid_locator2 = angle_helper.LocatorD(6, include_last=False)

        # Format the values of the grid
        tick_formatter1 = self.create_tick_formatter()
        tick_formatter2 = angle_helper.FormatterDMS()

        grid_helper = GridHelperCurveLinear(
            (tr, inv_tr),
            extreme_finder=extreme_finder,
            grid_locator1=grid_locator1,
            grid_locator2=grid_locator2,
            tick_formatter1=tick_formatter1,
            tick_formatter2=tick_formatter2,
        )

        fig = plt.gcf()
        rect = self.ax.get_position()
        ax = axisartist.Axes(fig, rect, grid_helper=grid_helper, frameon=False)
        fig.add_axes(ax)

        # Coordinate formatter
        def format_coord(x, y):
            return 'lon=%1.4f, lat=%1.4f' % inv_tr(x, y)

        ax.format_coord = format_coord
        ax.axis['left'].major_ticklabels.set_visible(True)
        ax.axis['right'].major_ticklabels.set_visible(False)
        ax.axis['bottom'].major_ticklabels.set_visible(True)
        ax.axis['top'].major_ticklabels.set_visible(True)

        ax.axis['bottom'].label.set(text="Right Ascension", size=18)
        ax.axis['left'].label.set(text="Declination", size=18)
        self.aa = ax

        # Set the current axis back to the SkyAxes
        fig.sca(self.ax)

        return fig, ax
コード例 #3
0
ファイル: Axislinestyles.py プロジェクト: nigaknight/Practice
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(1)
ax = AA.Axes(fig, [0.1, 0.1, 0.8, 0.8])
fig.add_axes(ax)
ax.axis["right"].set_visible(False)
ax.axis["top"].set_visible(False)
plt.show()
コード例 #4
0
ファイル: survey.py プロジェクト: ste1d/skymap
    def create_axes(self,rect=111):
        """
        Create a special AxisArtist to overlay grid coordinates.

        Much of this taken from the examples here:
        http://matplotlib.org/mpl_toolkits/axes_grid/users/axisartist.html
        """

        # from curved coordinate to rectlinear coordinate.
        def tr(x, y):
            x, y = np.asarray(x), np.asarray(y)
            return self(x,y)

        # from rectlinear coordinate to curved coordinate.
        def inv_tr(x,y):
            x, y = np.asarray(x), np.asarray(y)
            return self(x,y,inverse=True)


        # Cycle the coordinates
        extreme_finder = angle_helper.ExtremeFinderCycle(20, 20)

        # Find a grid values appropriate for the coordinate.
        # The argument is a approximate number of grid lines.
        grid_locator1 = angle_helper.LocatorD(9,include_last=False)
        #grid_locator1 = angle_helper.LocatorD(8,include_last=False)
        grid_locator2 = angle_helper.LocatorD(6,include_last=False)

        # Format the values of the grid
        tick_formatter1 = self.create_tick_formatter()
        tick_formatter2 = angle_helper.FormatterDMS()

        grid_helper = GridHelperCurveLinear((tr, inv_tr),
                                            extreme_finder=extreme_finder,
                                            grid_locator1=grid_locator1,
                                            grid_locator2=grid_locator2,
                                            tick_formatter1=tick_formatter1,
                                            tick_formatter2=tick_formatter2,
        )

        fig = plt.gcf()
        if rect is None:
            # This doesn't quite work. Need to remove the existing axis...
            rect = plt.gca().get_position()
            plt.gca().axis('off')
            ax = axisartist.Axes(fig,rect,grid_helper=grid_helper)
            fig.add_axes(ax)
        else:
            ax = axisartist.Subplot(fig,rect,grid_helper=grid_helper)
            fig.add_subplot(ax)

        ## Coordinate formatter
        def format_coord(x, y):
            return 'lon=%1.4f, lat=%1.4f'%inv_tr(x,y)
        ax.format_coord = format_coord
        ax.axis['left'].major_ticklabels.set_visible(True)
        ax.axis['right'].major_ticklabels.set_visible(False)
        ax.axis['bottom'].major_ticklabels.set_visible(True)
        ax.axis['top'].major_ticklabels.set_visible(True)

        ax.set_xlabel("Right Ascension")
        ax.set_ylabel("Declination")
        #self.set_axes_limits()

        self.axisartist = ax
        return fig,ax
コード例 #5
0
def main():

    origin = [0, 0]
    xCoord = [1, -1]
    yCoord = [1, 2]
    transformation = [[1, 3], [5, 2]]
    [eigenvalue1, eigenvalue2], [eigenvector1,
                                 eigenvector2] = LA.eig(transformation)
    print eigenvalue1, eigenvalue2, (3 - sqrt(61)) / 2, (3 + sqrt(61)) / 2
    eigenvector1 = eigenvector1 / dot(eigenvector1, eigenvector1)
    eigenvector2 = eigenvector2 / dot(eigenvector2, eigenvector2)
    eigenCoord1 = zip(origin, 3 * eigenvalue1 * eigenvector1)
    print eigenvector1

    fig, ax = plt.subplots()
    x_grid_locator = MaxNLocator(3 // 0.0125)
    y_grid_locator = MaxNLocator(3 // 0.00625)
    ax = AA.Axes(
        fig, [0.1, 0.1, 0.8, 0.8],
        grid_helper=GridHelperCurveLinear(
            (tr, inv_tr),
            grid_locator1=x_grid_locator,
            grid_locator2=y_grid_locator))  # This appears to be your margins
    fig.add_axes(ax)
    ax.axis["right"].set_visible(False)
    ax.axis["top"].set_visible(False)
    ax.axis["left"].set_visible(False)
    ax.axis["bottom"].set_visible(False)
    ax.grid(True, zorder=0)
    # ax.set_xticks([0.01, 0.02, 0.03])
    ax.axis["t"] = ax.new_floating_axis(
        0, 0
    )  # first argument appears to be slope, second argument appears to be starting point on vertical
    ax.axis["t2"] = ax.new_floating_axis(1, 0)
    # ax.axis["t"].set_xticks([1, 2, 3, 4, 5, 6])
    # ax.axis["t"].label.set_pad(2)
    ax.plot([0, 1], [0, 1])
    # ax.axis["y=0"] = ax.new_floating_axis(nth_coord=0, value=0)
    # # ax.axis["x=0"] = ax.new_floating_axis(nth_coord=0, value=0)
    # ax.axis["right2"] = ax.new_fixed_axis(loc="right", offset=(-184, 0))
    # ax.axis["t"] = ax.new_floating_axis(0, 0) # first argument appears to be slope, second argument appears to be starting point on vertical
    # ax.axis["t2"] = ax.new_floating_axis(1, 0)
    scalingFactor = (24 * sqrt(29)) / 5
    otherFactor = 12 * sqrt(5)
    print scalingFactor / 3
    print otherFactor / 3
    ax.set_xlim(-scalingFactor, scalingFactor)
    ax.set_ylim(-otherFactor, otherFactor)
    ax.quiver(origin,
              origin,
              xCoord,
              yCoord,
              color=[colorDefault(0), colorDefault(3)],
              angles='xy',
              scale_units='xy',
              scale=1)
    ax.grid(True, which='both')
    ax.axhline(y=0, color='k')
    ax.axvline(x=0, color='k')
    # axis_to_data = ax.transAxes + ax.transData.inverted()
    # points_data = axis_to_data.transform((2, 3))
    # data_to_axis = axis_to_data.inverted()
    # numpy.testing.assert_allclose((2, 3), data_to_axis.transform(points_data))
    plt.xlim(-8, 8)
    plt.ylim(-8, 8)

    plt.figure()
    plt.quiver(origin,
               origin,
               xCoord,
               yCoord,
               color=[colorDefault(0), colorDefault(3)],
               angles='xy',
               scale_units='xy',
               scale=1)
    plt.grid(True, which='both')
    plt.axhline(y=0, color='k')
    plt.axvline(x=0, color='k')
    # axis_to_data = ax.transAxes + ax.transData.inverted()
    # points_data = axis_to_data.transform((2, 3))
    # data_to_axis = axis_to_data.inverted()
    # numpy.testing.assert_allclose((2, 3), data_to_axis.transform(points_data))
    plt.xlim(-8, 8)
    plt.ylim(-8, 8)

    fig = plt.figure()
    x_grid_locator = MaxNLocator(3 // 0.0125)
    y_grid_locator = MaxNLocator(3 // 0.00625)
    ax = AA.Axes(
        fig, [0.1, 0.1, 0.8, 0.8],
        grid_helper=GridHelperCurveLinear(
            (tr, inv_tr),
            grid_locator1=x_grid_locator,
            grid_locator2=y_grid_locator))  # This appears to be your margins
    fig.add_axes(ax)
    ax.axis["right"].set_visible(False)
    ax.axis["top"].set_visible(False)
    ax.axis["left"].set_visible(False)
    ax.axis["bottom"].set_visible(False)
    ax.grid(True, zorder=0)
    # ax.set_xticks([0.01, 0.02, 0.03])
    ax.axis["t"] = ax.new_floating_axis(
        0, 0
    )  # first argument appears to be slope, second argument appears to be starting point on vertical
    ax.axis["t2"] = ax.new_floating_axis(1, 0)
    # ax.axis["t"].set_xticks([1, 2, 3, 4, 5, 6])
    # ax.axis["t"].label.set_pad(2)
    ax.plot([0, 1], [0, 1])
    # ax.axis["y=0"] = ax.new_floating_axis(nth_coord=0, value=0)
    # # ax.axis["x=0"] = ax.new_floating_axis(nth_coord=0, value=0)
    # ax.axis["right2"] = ax.new_fixed_axis(loc="right", offset=(-184, 0))
    # ax.axis["t"] = ax.new_floating_axis(0, 0) # first argument appears to be slope, second argument appears to be starting point on vertical
    # ax.axis["t2"] = ax.new_floating_axis(1, 0)
    scalingFactor = (24 * sqrt(29)) / 5
    otherFactor = 12 * sqrt(5)
    print scalingFactor / 3
    print otherFactor / 3
    ax.set_xlim(-scalingFactor, scalingFactor)
    ax.set_ylim(-otherFactor, otherFactor)

    plt.show()
コード例 #6
0
        axGrad.set_xlim(x1, x2)
        axGrad.set_ylim(-0.2, 0.5)

        # Löschen der Einträge xdata und ydata und anschließendes initialisieren der Daten von line

        line.set_data([], [])
        lineGrad.set_data([], [])

        axGrad.add_patch(patch)

        return

    # Fenster erstellen

    fig = plt.figure(figsize=(8, 8))
    ax = AA.Axes(fig, [0.1, 0.25, 0.8, 0.7])
    axGrad = AA.Axes(fig, [0.1, 0.1, 0.8, 0.05])
    fig.add_axes(ax)
    fig.add_axes(axGrad)
    axGrad.set_xticks(np.array([x1, x2]))

    axGrad.axis["right"].set_visible(False)
    axGrad.axis["top"].set_visible(False)
    axGrad.axis["left"].set_visible(False)

    # Plotten der Originalen Funktion
    xOrig = np.arange(x1, x2, 0.01)
    yOrig = f(xOrig)
    ax.plot(xOrig, yOrig)

    # Erzeugung des Gitters vom Koordinatensystem mit grid() und Deklaration der Daten