コード例 #1
0
ファイル: angdist.py プロジェクト: xdic/pyem
def setup_axes(fig, rect, rmax):
    tr_rotate = Affine2D().translate(0, 0)
    tr_scale = Affine2D().scale(np.pi / 180, 1)
    tr = tr_rotate + tr_scale + PolarTransform()
    grid_locator1 = angle_helper.LocatorDMS(12)
    grid_locator2 = angle_helper.LocatorDMS(3)
    tick_formatter1 = angle_helper.FormatterDMS()
    tick_formatter2 = angle_helper.FormatterDMS()
    ra0, ra1 = 0, 180
    cz0, cz1 = 0, rmax
    grid_helper = floating_axes.GridHelperCurveLinear(
        tr, extremes=(ra0, ra1, cz0, cz1),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=tick_formatter2)
    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)
    ax1.axis["left"].set_axis_direction("bottom")
    ax1.axis["right"].set_axis_direction("top")
    ax1.axis["bottom"].set_visible(False)
    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")
    ax1.axis["top"].label.set_text("Tilt Angle")
    aux_ax = ax1.get_aux_axes(tr)
    aux_ax.patch = ax1.patch
    ax1.patch.zorder = 0.9
    return ax1, aux_ax
コード例 #2
0
def setup_axes2(fig, rect):
    #mengatur locator dan formatter
    tr = PolarAxes.PolarTransform()
    pi = np.pi
    angle_ticks = [(0, r"$0$"), (.25 * pi, r"$\frac{1}{4}\pi$"),
                   (.5 * pi, r"$\frac{1}{2}\pi$")]
    grid_locator1 = FixedLocator([v for v, s in angle_ticks])
    tick_formatter1 = DictFormatter(dict(angle_ticks))
    grid_locator2 = MaxNLocator(2)
    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(.5 * pi, 0, 2, 1),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None,
    )

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    aux_ax = ax1.get_aux_axes(tr)

    aux_ax.patch = ax1.patch
    ax1.patch.zorder = 0.9
    return ax1, aux_ax
コード例 #3
0
def setup_axes2(fig, rect):
    tr = PolarAxes.PolarTransform()

    pi = np.pi
    angle_ticks = [(0, r"$0$"), (.25 * pi, r"$\frac{1}{4}\pi$"),
                   (.5 * pi, r"$\frac{1}{2}\pi$")]
    grid_locator1 = FixedLocator([v for v, s in angle_ticks])
    tick_formatter1 = DictFormatter(dict(angle_ticks))

    grid_locator2 = MaxNLocator(2)

    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(.5 * pi, 0, 2, 1),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None)

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    # 创建一个ParasiteAxes
    aux_ax = ax1.get_aux_axes(tr)

    # 让aux_ax具有一个ax中的剪切路径
    aux_ax.patch = ax1.patch
    # 但这样做会有一个副作用,这个patch会被绘制两次,并且可能会被绘制于其它
    # Artist的上面,因此用降低其zorder值的方法来阻止该情况
    ax1.patch.zorder = 0.9

    return ax1, aux_ax
コード例 #4
0
def taylor(scores):
    fig = plt.figure(1)
    tr = PolarAxes.PolarTransform()
    
    CCgrid= np.concatenate((np.arange(0,10,2)/10.,[0.9,0.95,0.99]))
    CCpolar=np.arccos(CCgrid)
    gf=FixedLocator(CCpolar)
    tf=DictFormatter(dict(zip(CCpolar, map(str,CCgrid))))
    
    STDgrid=np.arange(0,2.0,.5)
    gfs=FixedLocator(STDgrid)
    tfs=DictFormatter(dict(zip(STDgrid, map(str,STDgrid))))
    
    ra0, ra1 =0, np.pi/2
    cz0, cz1 = 0, 2
    grid_helper = floating_axes.GridHelperCurveLinear(
        tr, extremes=(ra0, ra1, cz0, cz1),
        grid_locator1=gf,
        tick_formatter1=tf,
        grid_locator2=gfs,
        tick_formatter2=tfs)

    ax1 = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
    fig.add_subplot(ax1)
    
    ax1.axis["top"].set_axis_direction("bottom")  
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")
    ax1.axis["top"].label.set_text("Correlation")

    
    
    ax1.axis["left"].set_axis_direction("bottom") 
    ax1.axis["left"].label.set_text("Normalized Standard deviation")

    ax1.axis["right"].set_axis_direction("top")  
    ax1.axis["right"].toggle(ticklabels=True)
    ax1.axis["right"].major_ticklabels.set_axis_direction("left")
    
    ax1.axis["bottom"].set_visible(False) 
    ax1 = ax1.get_aux_axes(tr)
    
    rs,ts = np.meshgrid(np.linspace(0,2),np.linspace(0,np.pi/2))
    rms = np.sqrt(1 + rs**2 - 2*rs*np.cos(ts))
        
    contours = ax1.contour(ts, rs, rms, 3,colors='0.5')   
    plt.clabel(contours, inline=1, fontsize=10)
    plt.grid(linestyle=':',alpha=0.5) 
        
    
    for r in scores.iterrows():
        th=np.arccos(r[1].CORRELATION)
        rr=r[1].MSTD/r[1].OSTD
        
        ax1.plot(th,rr,'o',label=r[0])
        
    plt.legend(loc='upper right',bbox_to_anchor=[1.2,1.15])    
    plt.show()
コード例 #5
0
ファイル: box3d.py プロジェクト: pencil-code/pencil-code
    def plot(self):
        """
        Plot the 3d box.
        """

        import pylab as plt
        from matplotlib.transforms import Affine2D
        import mpl_toolkits.axisartist.floating_axes as floating_axes

        # Prepare the plot.
        width = 6
        height = 5
        plt.rc("text", usetex=True)
        plt.rc("font", family="arial")
        plt.rc("figure.subplot", left=0.15)
        plt.rc("figure.subplot", right=0.90)
        plt.rc("figure.subplot", bottom=0.15)
        plt.rc("figure.subplot", top=0.95)
        fig = plt.figure(figsize=(width, height))

        # Top slice.
        data = self.slices[0]
        transformation = Affine2D().scale(0.5, 0.5).rotate_deg(45).translate(
            0, 0.5)
        grid_helper = floating_axes.GridHelperCurveLinear(transformation,
                                                          extremes=(0, 1, 0,
                                                                    1))
        axes = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
        fig.add_subplot(axes)
        aux_axes = axes.get_aux_axes(transformation)
        aux_axes.imshow(data, extent=[0, 1, 0, 1])

        # Left slice.
        data = self.slices[1]
        transformation = (Affine2D().scale(0.5, 0.5).rotate_deg(45).translate(
            0, 0.5).skew_deg(20, 40))
        grid_helper = floating_axes.GridHelperCurveLinear(transformation,
                                                          extremes=(0, 1, 0,
                                                                    1))
        axes = floating_axes.FloatingSubplot(fig, 121, grid_helper=grid_helper)
        fig.add_subplot(axes)
        aux_axes = axes.get_aux_axes(transformation)
        aux_axes.imshow(data, extent=[0, 1, 0, 1])

        if len(self.slices) > 3:
            pass
コード例 #6
0
def setup_axes3(fig, rect):
    """
    Sometimes, things like axis_direction need to be adjusted.
    """

    # rotate a bit for better orientation
    tr_rotate = Affine2D().translate(-95, 0)

    # scale degree to radians
    tr_scale = Affine2D().scale(np.pi / 180., 1.)

    tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()

    grid_locator1 = angle_helper.LocatorHMS(4)
    tick_formatter1 = angle_helper.FormatterHMS()

    grid_locator2 = MaxNLocator(3)

    # Specify theta limits in degrees
    ra0, ra1 = 8. * 15, 14. * 15
    # Specify radial limits
    cz0, cz1 = 0, 14000
    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(ra0, ra1, cz0, cz1),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None)

    ax1 = fig.add_subplot(rect,
                          axes_class=floating_axes.FloatingAxes,
                          grid_helper=grid_helper)

    # adjust axis
    ax1.axis["left"].set_axis_direction("bottom")
    ax1.axis["right"].set_axis_direction("top")

    ax1.axis["bottom"].set_visible(False)
    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")

    ax1.axis["left"].label.set_text(r"cz [km$^{-1}$]")
    ax1.axis["top"].label.set_text(r"$\alpha_{1950}$")

    # create a parasite axes whose transData in RA, cz
    aux_ax = ax1.get_aux_axes(tr)

    aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
    ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
    # drawn twice, and possibly over some other
    # artists. So, we decrease the zorder a bit to
    # prevent this.

    return ax1, aux_ax
コード例 #7
0
def taylor_template(angle_lim, std_lim, rect, xaxislab, fig=None):
    # written by Maria Aristizabal: https://github.com/MariaAristizabal/Evaluation_surf_metrics_Dorian_figures
    import mpl_toolkits.axisartist.floating_axes as floating_axes
    from matplotlib.projections import PolarAxes
    from mpl_toolkits.axisartist.grid_finder import (FixedLocator,
                                                     DictFormatter)

    if fig is None:
        fig = plt.figure()
    tr = PolarAxes.PolarTransform()

    min_corr = np.round(np.cos(angle_lim), 1)
    CCgrid = np.concatenate(
        (np.arange(min_corr * 10, 10, 2.0) / 10., [0.9, 0.95, 0.99]))
    CCpolar = np.arccos(CCgrid)
    gf = FixedLocator(CCpolar)
    tf = DictFormatter(dict(zip(CCpolar, map(str, CCgrid))))

    STDgrid = np.arange(0, std_lim, .5)
    gfs = FixedLocator(STDgrid)
    tfs = DictFormatter(dict(zip(STDgrid, map(str, STDgrid))))

    ra0, ra1 = 0, angle_lim
    cz0, cz1 = 0, std_lim
    grid_helper = floating_axes.GridHelperCurveLinear(tr,
                                                      extremes=(ra0, ra1, cz0,
                                                                cz1),
                                                      grid_locator1=gf,
                                                      tick_formatter1=tf,
                                                      grid_locator2=gfs,
                                                      tick_formatter2=tfs)

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")
    ax1.axis["top"].label.set_text("Correlation")
    ax1.axis['top'].label.set_size(14)

    ax1.axis["left"].set_axis_direction("bottom")
    if xaxislab == 'yes':
        ax1.axis["left"].label.set_text("Normalized Standard Deviation")
    ax1.axis['left'].label.set_size(14)

    ax1.axis["right"].set_axis_direction("top")
    ax1.axis["right"].toggle(ticklabels=True)
    ax1.axis["right"].major_ticklabels.set_axis_direction("left")

    ax1.axis["bottom"].set_visible(False)
    ax1 = ax1.get_aux_axes(tr)

    plt.grid(linestyle=':', alpha=0.5)

    return fig, ax1
コード例 #8
0
def rotate(fig, degree):
    """Rotation of plot with impossible-to-remove, rotated frame.
    """
    plot_extents = 0, 1, 0, 1
    transform = Affine2D().rotate_deg(degree)
    helper = floating_axes.GridHelperCurveLinear(transform, plot_extents)
    ax = floating_axes.FloatingSubplot(fig, 111, grid_helper=helper)
    fig.add_subplot(ax)
    aux_ax = ax.get_aux_axes(transform)
    return aux_ax
コード例 #9
0
def setup_earth_axes(fig, rect, theta_lim, h_lim, a_e, theta_scale):
    """
    From https://matplotlib.org/examples/axes_grid/demo_floating_axes.html
    """

    # rotate a bit for better orientation
    tr_rotate = Affine2D().translate(
        np.pi / 2 - np.mean(theta_lim) * theta_scale, 0)

    # scale degree to radians
    tr_scale = Affine2D().scale(theta_scale, 1)

    # treat heights
    tr_htrans = Affine2D().translate(0, +a_e)

    tr = tr_htrans + tr_scale + tr_rotate + PolarAxes.PolarTransform()

    grid_locator1 = MaxNLocator(5)
    grid_locator2 = MaxNLocator(5)

    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(*theta_lim, *h_lim),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=None,
        tick_formatter2=None,
    )

    ax = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)

    fig.add_subplot(ax)

    # adjust axis
    ax.axis["left"].set_axis_direction("top")
    ax.axis["left"].label.set_text("Height [m]")
    ax.axis["left"].toggle(ticklabels=True, label=True)
    ax.axis["right"].toggle(ticklabels=False, label=False)
    ax.axis["right"].set_axis_direction("right")
    ax.axis["bottom"].toggle(ticklabels=True, label=True)
    ax.axis["bottom"].set_axis_direction("bottom")
    ax.axis["bottom"].major_ticklabels.set_axis_direction("bottom")
    ax.axis["bottom"].label.set_axis_direction("bottom")
    ax.axis["bottom"].label.set_text("Distance [km]")

    # create a parasite axes whose transData in RA, cz
    aux_ax = ax.get_aux_axes(tr)

    aux_ax.patch = ax.patch  # for aux_ax to have a clip path as in ax
    ax.patch.zorder = 0.9  # but this has a side effect that the patch is
    # drawn twice, and possibly over some other
    # artists. So, we decrease the zorder a bit to
    # prevent this.

    return ax, aux_ax
コード例 #10
0
def setup_axes1(fig, rect):
    #salah satu penyederhanaan
    tr = Affine2D().scale(2, 1).rotate_deg(30)
    grid_helper = floating_axes.GridHelperCurveLinear(tr,
                                                      extremes=(0, 4, 0, 4))
    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)
    aux_ax = ax1.get_aux_axes(tr)
    grid_helper.grid_finder.grid_locator1._nbins = 4
    grid_helper.grid_finder.grid_locator2._nbins = 4
    return ax1, aux_ax
コード例 #11
0
def setup_axes3(fig, rect):
    """
    Sometimes, things like axis_direction need to be adjusted.
    """

    # scale degree to radians
    tr_scale = Affine2D().scale(np.pi / 180., 1.)

    tr = tr_scale + PolarAxes.PolarTransform()

    grid_locator1 = angle_helper.LocatorHMS(4)
    tick_formatter1 = angle_helper.FormatterHMS()

    grid_locator2 = MaxNLocator(3)

    ra0, ra1 = 0, 180
    cz0, cz1 = 0, 10
    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(ra0, ra1, cz0, cz1),
        #grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        #tick_formatter1=tick_formatter1,
        tick_formatter2=None,
    )

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    # adjust axis
    ax1.axis["left"].set_axis_direction("bottom")
    ax1.axis["right"].set_axis_direction("top")

    ax1.axis["bottom"].set_visible(False)
    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")

    ax1.axis["left"].label.set_text(r"$P(\alpha)$")
    ax1.axis["top"].label.set_text(r"$\alpha$")

    # create a parasite axes whose transData in RA, cz
    aux_ax = ax1.get_aux_axes(tr)

    aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
    ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
    # drawn twice, and possibly over some other
    # artists. So, we decrease the zorder a bit to
    # prevent this.

    return ax1, aux_ax
コード例 #12
0
ファイル: viz.py プロジェクト: monfera/ecogtools
def add_rotated_axis(f,
                     extents=(-1, 1, 0, 1),
                     sc_x=None,
                     sc_y=None,
                     rotation=45,
                     position=(.5, .5, .1, .1),
                     invisible_border=True):
    """Add a rotated axis to an existing figure.

    Parameters
    ----------
    f : mpl.figure
        The figure you're adding a axis to.
    extents : tuple, shape of ints (4,)
        The x min/max and y min/max of the axis, as well as axis data boundaries.
    sc_x : float
        How much to scale the x-axis for shaping nicely
    sc_y : float
        How much to scale the y_axis for shaping nicely
    rotation : float
        Rotation of the axis
    position : tuple of floats, shape (2,)
        The position of the axis as a fraction of the figure
    invisible_border : bool
        Whether to make elements of the axis invisible

    Returns
    -------
    ax : mpl axis object
        The axis you've added
    ax_aux : mpl auxilliary axis object
        The auxilliary object of the axis you've added. This
        is useful for doing certain kinds of transformations that
        aren't possible with the regular axis.
    """
    af = Affine2D()
    transform = af.scale(sc_x, sc_y).rotate_deg(rotation)
    helper = floating_axes.GridHelperCurveLinear(transform, extents)
    ax = floating_axes.FloatingSubplot(f, 111, grid_helper=helper)
    ax_aux = ax.get_aux_axes(transform)
    f.add_subplot(ax)
    ax.set_position(position)
    ax.invert_xaxis()

    if invisible_border is True:
        # Strip axis elements
        ax.patch.set(visible=False)
        for axis in ax.axis.values():
            axis.set_visible(False)

    return ax, ax_aux
コード例 #13
0
def setup_axes3(fig, rect):
    # 将坐标轴稍微旋转一下
    tr_rotate = Affine2D().translate(-95, 0)

    # 转换弧度与度
    tr_scale = Affine2D().scale(np.pi / 180., 1.)

    tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()

    grid_locator1 = angle_helper.LocatorHMS(4)
    tick_formatter1 = angle_helper.FormatterHMS()

    grid_locator2 = MaxNLocator(3)

    # 设置theta的数值范围,以度为单位
    ra0, ra1 = 8. * 15, 14. * 15
    # 设置径向的数值范围
    cz0, cz1 = 0, 14000
    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(ra0, ra1, cz0, cz1),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None)

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    # 调整axis
    ax1.axis["left"].set_axis_direction("bottom")
    ax1.axis["right"].set_axis_direction("top")

    ax1.axis["bottom"].set_visible(False)
    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")

    ax1.axis["left"].label.set_text(r"cz [km$^{-1}$]")
    ax1.axis["top"].label.set_text(r"$\alpha_{1950}$")

    # 创建ParasiteAxes,其transData在(RA, cz)空间
    aux_ax = ax1.get_aux_axes(tr)

    # 让aux_ax具有一个ax中的剪切路径,并降低其zorder值
    aux_ax.patch = ax1.patch
    ax1.patch.zorder = 0.9

    return ax1, aux_ax
コード例 #14
0
def skymap():
    theta = np.radians(ra[(matom_disk != 0) & (matom_disk > 10**6)])
    radius = zcos[(matom_disk != 0) & (matom_disk > 10**6)]

    # theta = np.random.uniform(low=0.0,high=60.0,size=(500,))
    # radius = np.random.uniform(low=0.0,high=1.0,size=(500,))

    thetaLims = (0.0, np.radians(60.0))

    zLims = (0.0, 0.07)

    fig = plt.figure(figsize=(24, 20))

    tr = PolarAxes.PolarTransform()
    grid_helper = floating_axes.GridHelperCurveLinear(tr,
                                                      extremes=(*thetaLims,
                                                                *zLims))

    ax = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
    fig.add_subplot(ax)

    # adjust axis
    ax.axis["left"].set_axis_direction("bottom")
    ax.axis["right"].set_axis_direction("top")
    ax.axis["bottom"].set_visible(False)
    ax.axis["top"].set_axis_direction("bottom")
    ax.axis["top"].toggle(ticklabels=True, label=True)
    ax.axis["top"].major_ticklabels.set_axis_direction("top")
    ax.axis["top"].label.set_axis_direction("top")
    ax.axis["left"].label.set_text(r"z")
    ax.axis["top"].label.set_text(r"RA")

    # create a parasite axes whose transData in RA, cz

    aux_ax = ax.get_aux_axes(tr)
    aux_ax.patch = ax.patch
    ax.patch.zorder = 0.9

    scatter_yo = aux_ax.scatter(theta,
                                radius,
                                s=0.5,
                                c=np.log10(matom_disk[(matom_disk != 0)
                                                      & (matom_disk > 10**6)]),
                                cmap='plasma')
    aux_ax.grid(True)
    aux_ax.set_axisbelow(True)
    cbar = plt.colorbar(scatter_yo, orientation='horizontal', shrink=0.7)
    plt.title('Lightcone - cosmological z - All ')
    cbar.ax.set_title('$log_{10}[M_{HI}$ / ($M_{\odot}$)]', size=14)
    plt.show()
コード例 #15
0
def taylor_template(angle_lim, std_lim):

    fig = plt.figure()
    tr = PolarAxes.PolarTransform()

    min_corr = np.round(np.cos(angle_lim), 1)
    CCgrid = np.concatenate(
        (np.arange(min_corr * 10, 10, 2.0) / 10., [0.9, 0.95, 0.99]))
    CCpolar = np.arccos(CCgrid)
    gf = FixedLocator(CCpolar)
    tf = DictFormatter(dict(zip(CCpolar, map(str, CCgrid))))

    STDgrid = np.arange(0, std_lim, .5)
    gfs = FixedLocator(STDgrid)
    tfs = DictFormatter(dict(zip(STDgrid, map(str, STDgrid))))

    ra0, ra1 = 0, angle_lim
    cz0, cz1 = 0, std_lim
    grid_helper = floating_axes.GridHelperCurveLinear(tr,
                                                      extremes=(ra0, ra1, cz0,
                                                                cz1),
                                                      grid_locator1=gf,
                                                      tick_formatter1=tf,
                                                      grid_locator2=gfs,
                                                      tick_formatter2=tfs)

    ax1 = floating_axes.FloatingSubplot(fig, 111, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")
    ax1.axis["top"].label.set_text("Correlation")
    ax1.axis['top'].label.set_size(14)

    ax1.axis["left"].set_axis_direction("bottom")
    ax1.axis["left"].label.set_text("Normalized Standard Deviation")
    ax1.axis['left'].label.set_size(14)

    ax1.axis["right"].set_axis_direction("top")
    ax1.axis["right"].toggle(ticklabels=True)
    ax1.axis["right"].major_ticklabels.set_axis_direction("left")

    ax1.axis["bottom"].set_visible(False)
    ax1 = ax1.get_aux_axes(tr)

    plt.grid(linestyle=':', alpha=0.5)

    return fig, ax1
コード例 #16
0
def setup_axes1(fig, rect):
    tr = Affine2D().scale(2, 1).rotate_deg(30)

    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(-0.5, 3.5, 0, 4),
        grid_locator1=MaxNLocator(nbins=4),
        grid_locator2=MaxNLocator(nbins=4))

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    aux_ax = ax1.get_aux_axes(tr)

    return ax1, aux_ax
コード例 #17
0
def setup_axes1(fig, rect):
    """
    A simple one.
    """
    tr = Affine2D().scale(2, 1).rotate_deg(30)

    grid_helper = floating_axes.GridHelperCurveLinear(tr, extremes=(0, 4, 0, 4))

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    grid_helper.grid_finder.grid_locator1._nbins = 4
    grid_helper.grid_finder.grid_locator2._nbins = 4

    return ax1
コード例 #18
0
def add_rotated_axes(fig, rect=111, angle=-45):
    """ Add a rotated axes to figure fig.
    """
    tr = Affine2D().scale(1, 1).rotate_deg(angle)

    grid_helper = floating_axes.GridHelperCurveLinear(tr, extremes=(0, 1, 0, 1))

    ax = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_axes(ax)

    aux_ax = ax.get_aux_axes(tr)

    #grid_helper.grid_finder.grid_locator1._nbins = 4
    #grid_helper.grid_finder.grid_locator2._nbins = 4

    return ax, aux_ax
コード例 #19
0
    def setup_axes(fig, rect, extremes):
        """Axes for a GAMA region"""

        # rotate a bit for better orientation
        tr_rotate = Affine2D().translate(-0.5 * (extremes[0] + extremes[1]), 0)

        # scale degree to radians
        tr_scale = Affine2D().scale(np.pi / 180., 1.)

        tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()

        grid_locator1 = MaxNLocator(3)

        grid_locator2 = MaxNLocator(5)

        grid_helper = floating_axes.GridHelperCurveLinear(
            tr,
            extremes=extremes,
            grid_locator1=grid_locator1,
            grid_locator2=grid_locator2)

        ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
        fig.add_subplot(ax1)

        # adjust axis
        ax1.axis["left"].set_axis_direction("bottom")
        ax1.axis["right"].set_axis_direction("top")

        ax1.axis["bottom"].set_visible(False)
        ax1.axis["top"].set_axis_direction("bottom")
        ax1.axis["top"].toggle(ticklabels=True, label=True)
        ax1.axis["top"].major_ticklabels.set_axis_direction("top")
        ax1.axis["top"].label.set_axis_direction("top")

        ax1.axis["left"].label.set_text(r'z')
        ax1.axis["top"].label.set_text('RA [deg]')

        # create a parasite axes whose transData in RA, z
        aux_ax = ax1.get_aux_axes(tr)

        aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
        ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
        # drawn twice, and possibly over some other
        # artists. So, we decrease the zorder a bit to
        # prevent this.

        return ax1, aux_ax
コード例 #20
0
    def setup_axes2(self, fig, rect, n_markers, lat_min, lat_max, angle_ticks):
        """
        for thin shells, lat subset 
        """

        tr = PolarAxes.PolarTransform()

        rs = np.linspace(self.r_inner, self.r_outer, n_markers)

        if not angle_ticks:
            angle_ticks = []

        grid_locator1 = FixedLocator([v for v, s in angle_ticks])
        tick_formatter1 = DictFormatter(dict(angle_ticks))

        # set the number of r points you want on plot
        grid_locator2 = FixedLocator(rs)
        tick_formatter2 = None

        grid_helper = floating_axes.GridHelperCurveLinear(
            tr,
            extremes=(lat_max / 180 * np.pi, lat_min / 180 * np.pi,
                      self.r_outer, self.r_inner),  # 70/180
            grid_locator1=grid_locator1,
            grid_locator2=grid_locator2,
            tick_formatter1=tick_formatter1,
            tick_formatter2=tick_formatter2)

        ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
        fig.add_subplot(ax1)

        # format tick labels (see: https://matplotlib.org/mpl_toolkits/axes_grid/users/axisartist.html)
        ax1.axis["bottom"].major_ticklabels.set_rotation(-90)
        ax1.axis["bottom"].major_ticklabels.set_va("center")
        ax1.axis["bottom"].major_ticklabels.set_pad(12)

        # create a parasite axes whose transData in RA, cz
        aux_ax = ax1.get_aux_axes(tr)

        aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
        ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
        # drawn twice, and possibly over some other
        # artists. So, we decrease the zorder a bit to
        # prevent this.

        return ax1, aux_ax
コード例 #21
0
def setup_axes1(fig, rect):
    """
    Get a simple floating cartesian axis rotated at 25 degrees
    """
    tr = Affine2D().scale(1, 1).rotate_deg(25)

    grid_helper = floating_axes.GridHelperCurveLinear(tr,
                                                      extremes=(0, 4, 0, 4))

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    aux_ax = ax1.get_aux_axes(tr)

    grid_helper.grid_finder.grid_locator1._nbins = 4
    grid_helper.grid_finder.grid_locator2._nbins = 4

    return ax1, aux_ax
コード例 #22
0
ファイル: POLCOL_tools.py プロジェクト: RRPJ/POLCOL
def setup_axes(fig, rect, theta, radius):
    """ Sets up the axes in such a way we can plot the polarplot. """

    tr = PolarAxes.PolarTransform()

    pi = np.pi
    angle_ticks = [(-4. / 8. * pi, r"$-\frac{1}{2}\pi$"), (-3. / 8. * pi, r""),
                   (-2. / 8. * pi, r"$-\frac{1}{4}\pi$"), (-1. / 8. * pi, r""),
                   (0. / 8. * pi, r"$0$"), (1. / 8. * pi, r""),
                   (2. / 8. * pi, r"$\frac{1}{4}\pi$"), (3. / 8. * pi, r""),
                   (4. / 8. * pi, r"$\frac{1}{2}\pi$"),
                   (6. / 8. * pi, r"$\frac{3}{4}\pi$"),
                   (8. / 8. * pi, r"$\pi$")]

    grid_locator1 = FixedLocator([v for v, s in angle_ticks])
    tick_formatter1 = DictFormatter(dict(angle_ticks))
    grid_locator2 = MaxNLocator(3)

    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(theta[0], theta[1], radius[0], radius[1]),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None)

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    # adjust axis
    # "bottom", "top", "left", "right"
    ax1.axis["left"].set_axis_direction("bottom")
    ax1.axis["right"].set_axis_direction("top")

    ax1.axis["bottom"].set_visible(False)
    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")

    # create a parasite axes
    aux_ax = ax1.get_aux_axes(tr)

    return ax1, aux_ax
コード例 #23
0
def plot_taylor_diag(std, corr, ref_std, normalized=True):

    import mpl_toolkits.axisartist.grid_finder as gf
    import mpl_toolkits.axisartist.floating_axes as fa

    # define polar axes transform
    tr = PolarAxes.PolarTransform()

    # define correlation labels
    rlocs = np.concatenate((np.arange(10) / 10., [0.95, 0.99]))
    tlocs = np.arccos(rlocs)
    gl1 = gf.FixedLocator(tlocs)
    tf1 = gf.DictFormatter(dict(zip(tlocs, map(str, rlocs))))

    smin = 0
    smax = max(2.0, 1.1 * std.max())

    # add the curvilinear grid
    fig = plt.figure()

    ghelper = fa.GridHelperCurveLinear(tr,
                                       extremes=(0, np.pi / 2, smin, smax),
                                       grid_locator1=gl1,
                                       tick_formatter1=tf1)
    ax = fa.FloatingSubplot(fig, 111, grid_helper=ghelper)
    fig.add_subplot(ax)

    # adjust axes
    ax.axis["top"].set_axis_direction("bottom")
    ax.axis["top"].toggle(ticklabels=True, label=True)
    ax.axis["top"].major_ticklabels.set_axis_direction("top")
    ax.axis["top"].label.set_axis_direction("top")
    ax.axis["top"].label.set_text("Correlation")
    ax.axis["left"].set_axis_direction("bottom")
    if normalize:
        ax.axis["left"].label.set_text("Normalized standard deviation")
    else:
        ax.axis["left"].label.set_text("Standard deviation")
    ax.axis["right"].set_axis_direction("top")
    ax.axis["right"].toggle(ticklabels=True)
    ax.axis["right"].major_ticklabels.set_axis_direction("left")
    ax.axis["bottom"].set_visible(False)
    ax.grid(True)
コード例 #24
0
    def setup_axes(fig, rect, rotation, axisScale, axisLimits, doShift):
        tr_rot = Affine2D().scale(axisScale[0],
                                  axisScale[1]).rotate_deg(rotation)

        if doShift:
            tr_trn = Affine2D().translate(-90, -5)
        else:
            tr_trn = Affine2D().translate(0, 0)

        tr = tr_rot + tr_trn

        grid_helper = floating_axes.GridHelperCurveLinear(tr,
                                                          extremes=axisLimits)

        ax = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
        fig.add_subplot(ax)
        aux_ax = ax.get_aux_axes(tr)

        return ax, aux_ax
コード例 #25
0
ファイル: plot_ray_path.py プロジェクト: xblee2005/seis
def setup_axes2(fig, rect):
    """
    With custom locator and formatter.
    Note that the extreme values are swapped.
    """
    tr = PolarAxes.PolarTransform()

    pi = np.pi
    angle_ticks = [(.5 * pi, r"90$\degree$"), (.625 * pi, r"112.5$\degree$"),
                   (.75 * pi, r"135$\degree$"),
                   (.81111111 * pi, r"146$\degree$"),
                   (.84444444 * pi, r"152$\degree$"), (pi, r"180$\degree$")]
    grid_locator1 = FixedLocator([v for v, s in angle_ticks])
    tick_formatter1 = DictFormatter(dict(angle_ticks))

    grid_locator2 = MaxNLocator(2)

    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(pi, 0.5 * pi, 6371, 0),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None)

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    ax1.axis["bottom"].major_ticklabels.set_axis_direction("top")
    ax1.axis["left"].toggle(ticklabels=False)
    ax1.axis["left"].toggle(ticks=False)
    ax1.axis["top"].toggle(ticks=False)
    fig.add_subplot(ax1)

    # create a parasite axes whose transData in RA, cz
    aux_ax = ax1.get_aux_axes(tr)

    aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
    ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
    # drawn twice, and possibly over some other
    # artists. So, we decrease the zorder a bit to
    # prevent this.

    return ax1, aux_ax
コード例 #26
0
def setup_axes3(fig, rect):
    #menentukan axis_direction
    tr_rotate = Affine2D().translate(-95, 0)
    tr_scale = Affine2D().scale(np.pi / 180., 1.)
    tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()

    grid_locator1 = angle_helper.LocatorHMS(4)
    tick_formatter1 = angle_helper.FormatterHMS()

    grid_locator2 = MaxNLocator(3)
    ra0, ra1 = 8. * 15, 14. * 15
    cz0, cz1 = 0, 14000
    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(ra0, ra1, cz0, cz1),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None,
    )

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    ax1.axis["left"].set_axis_direction("bottom")
    ax1.axis["right"].set_axis_direction("top")

    ax1.axis["bottom"].set_visible("False")
    ax1.axis["top"].set_axis_direction("bottom")
    ax1.axis["top"].toggle(ticklabels=True, label=True)
    ax1.axis["top"].major_ticklabels.set_axis_direction("top")
    ax1.axis["top"].label.set_axis_direction("top")

    ax1.axis["left"].label.set_text(r"cz [km$^{-1}$]")
    ax1.axis["top"].label.set_text(r"$\alpha_{1950}$]")

    aux_ax = ax1.get_aux_axes(tr)
    aux_ax.patch = ax1.patch
    #efek dari patch adalah lebih sederhana dan lebih pada tampilan lainnya
    ax1.patch.zorder = 0.9
    return ax1, aux_ax
コード例 #27
0
def setup_axes2(fig, rect):
    """
    With custom locator and formatter.
    Note that the extreme values are swapped.
    """

    #tr_scale = Affine2D().scale(np.pi/180., 1.)

    tr = PolarAxes.PolarTransform()

    pi = np.pi
    angle_ticks = [(0, r"$0$"), (.25 * pi, r"$\frac{1}{4}\pi$"),
                   (.5 * pi, r"$\frac{1}{2}\pi$")]
    grid_locator1 = FixedLocator([v for v, s in angle_ticks])
    tick_formatter1 = DictFormatter(dict(angle_ticks))

    grid_locator2 = MaxNLocator(2)

    grid_helper = floating_axes.GridHelperCurveLinear(
        tr,
        extremes=(.5 * pi, 0, 2, 1),
        grid_locator1=grid_locator1,
        grid_locator2=grid_locator2,
        tick_formatter1=tick_formatter1,
        tick_formatter2=None,
    )

    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
    fig.add_subplot(ax1)

    # create a parasite axes whose transData in RA, cz
    aux_ax = ax1.get_aux_axes(tr)

    aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
    ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
    # drawn twice, and possibly over some other
    # artists. So, we decrease the zorder a bit to
    # prevent this.

    return ax1, aux_ax
コード例 #28
0
    def setup_axes(self, fig, rect, n_markers):
        """
        With custom locator and formatter.
        Note that the extreme values are swapped.
        """

        tr = PolarAxes.PolarTransform()

        rs = np.linspace(self.r_inner, self.r_outer, n_markers)

        angle_ticks = []

        grid_locator1 = FixedLocator([v for v, s in angle_ticks])
        tick_formatter1 = DictFormatter(dict(angle_ticks))

        # set the number of r points you want on plot
        grid_locator2 = FixedLocator(rs)
        tick_formatter2 = None

        grid_helper = floating_axes.GridHelperCurveLinear(
            tr,
            extremes=(0.5 * np.pi, -0.5 * np.pi, self.r_outer, self.r_inner),
            grid_locator1=grid_locator1,
            grid_locator2=grid_locator2,
            tick_formatter1=tick_formatter1,
            tick_formatter2=tick_formatter2)

        ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
        fig.add_subplot(ax1)

        # create a parasite axes whose transData in RA, cz
        aux_ax = ax1.get_aux_axes(tr)

        aux_ax.patch = ax1.patch  # for aux_ax to have a clip path as in ax
        ax1.patch.zorder = 0.9  # but this has a side effect that the patch is
        # drawn twice, and possibly over some other
        # artists. So, we decrease the zorder a bit to
        # prevent this.

        return ax1, aux_ax
コード例 #29
0
    def polarplot(self):

        tr = PolarAxes.PolarTransform()

        grid_locator1 = FixedLocator([v for v, s in self.angle_ticks])
        tick_formatter1 = DictFormatter(dict(self.angle_ticks))

        grid_locator2 = FixedLocator([a for a, b in self.radius_ticks])
        tick_formatter2 = DictFormatter(dict(self.radius_ticks))

        grid_helper = floating_axes.GridHelperCurveLinear(
            tr,
            extremes=(self.max_angle, self.min_angle, self.max_rad,
                      self.min_rad),
            grid_locator1=grid_locator1,
            grid_locator2=grid_locator2,
            tick_formatter1=tick_formatter1,
            tick_formatter2=tick_formatter2)

        ax = floating_axes.FloatingSubplot(self.fig,
                                           self.rect,
                                           grid_helper=grid_helper)
        self.fig.add_subplot(ax)
        ax.grid(True, color='b', linewidth=0.2, linestyle='-')

        aux_ax = ax.get_aux_axes(tr)
        aux_ax.patch = ax.patch
        ax.patch.zorder = 0.9

        ax.axis['bottom'].set_label(r'Angle ($^{\circ}$)')
        ax.axis['bottom'].major_ticklabels.set_rotation(180)
        ax.axis['bottom'].label.set_rotation(180)
        ax.axis['bottom'].LABELPAD += 30
        ax.axis['left'].set_label('Range (m)')
        ax.axis['left'].label.set_rotation(0)
        ax.axis['left'].LABELPAD += 15
        ax.axis['left'].set_visible(True)

        return ax, aux_ax
コード例 #30
0
def plot_frame(frame_id, lane_mod_coefs, C=None, c=None):
    x_min, x_max = 0.3, 1.5
    xps = np.linspace(x_min, x_max)
    yps = np.polyval(lane_mod_coefs[frame_id], xps)
    plt.plot(xps, yps, label='poly')
    if C is not None:
        xc, yc = C
        thetas = np.arctan2(yps - yc, xps - xc)
        Xcs = pt_on_circle(xc, yc, np.abs(1 / c), thetas)
        plt.plot(Xcs[:, 0], Xcs[:, 1], label='circle')
    ax = plt.gca()
    ax.axis('equal')
    pu.decorate(ax,
                'frame {}'.format(frame_id),
                xlab="x in m",
                ylab='y in m',
                legend=True)
    if 0:
        plot_extents = 0, 10, 0, 10
        transform = Affine2D().rotate_deg(45)
        helper = floating_axes.GridHelperCurveLinear(transform, plot_extents)
        ax = floating_axes.FloatingSubplot(plt.gcf, 111, grid_helper=helper)