Beispiel #1
0
def curvelinear_test2(fig, rect=111):
    """
    Polar projection, but in a rectangular box.
    """

    # see demo_curvelinear_grid.py for details
    tr = Affine2D().translate(0, 90) + Affine2D().scale(np.pi / 180., 1.) + \
        PolarAxes.PolarTransform()

    extreme_finder = angle_helper.ExtremeFinderCycle(
        10,
        60,
        lon_cycle=360,
        lat_cycle=None,
        lon_minmax=None,
        lat_minmax=(-90, np.inf),
    )
    # Changes theta gridline count
    grid_locator1 = angle_helper.LocatorHMS(12)
    grid_locator2 = angle_helper.LocatorDMS(6)
    tick_formatter1 = angle_helper.FormatterHMS()
    tick_formatter2 = angle_helper.FormatterDMS()

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

    ax1 = SubplotHost(fig, rect, grid_helper=grid_helper)

    # make ticklabels of right and top axis visible.
    ax1.axis["right"].major_ticklabels.set_visible(True)
    ax1.axis["top"].major_ticklabels.set_visible(True)
    ax1.axis["bottom"].major_ticklabels.set_visible(True)
    # let right and bottom axis show ticklabels for 1st coordinate (angle)
    ax1.axis["right"].get_helper().nth_coord_ticks = 0
    ax1.axis["bottom"].get_helper().nth_coord_ticks = 0

    #
    fig.add_subplot(ax1)

    grid_helper = ax1.get_grid_helper()

    # You may or may not need these - they set the view window explicitly
    # rather than using the default as determined by matplotlib with extreme
    # finder.
    ax1.set_aspect(1.)
    ax1.set_xlim(-4, 25)  # moves the origin left-right in ax1
    ax1.set_ylim(-2.5, 30)  # moves the origin up-down

    ax1.set_ylabel('$DEC\,(^{\circ})$')
    ax1.set_xlabel('$RA\,(h)$')
    ax1.grid(True)
    # ax1.grid(linestyle='--', which='x') # either keyword applies to both
    # ax1.grid(linestyle=':', which='y')  # sets of gridlines

    return ax1, tr
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
Beispiel #3
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
Beispiel #4
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
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
Beispiel #6
0
    def curvelinear_test2(fig, gs=None, xcenter=0.0, ycenter=17.3, xwidth=1.5, ywidth=1.5,
            rot_angle=0.0, xlabel=xlabel, ylabel=ylabel, xgrid_density=8, ygrid_density=5):
        """
        polar projection, but in a rectangular box.
        """

        tr = Affine2D().translate(0,90)
        tr += Affine2D().scale(np.pi/180., 1.)
        tr += PolarAxes.PolarTransform()

        tr += Affine2D().rotate(rot_angle)  # This rotates the grid

        extreme_finder = angle_helper.ExtremeFinderCycle(10, 60,
                                                        lon_cycle = 360,
                                                        lat_cycle = None,
                                                        lon_minmax = None,
                                                        lat_minmax = (-90, np.inf),
                                                        )

        grid_locator1 = angle_helper.LocatorHMS(xgrid_density) #changes theta gridline count
        tick_formatter1 = angle_helper.FormatterHMS()
        grid_locator2 = angle_helper.LocatorDMS(ygrid_density) #changes theta gridline count
        tick_formatter2 = angle_helper.FormatterDMS()


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

        # ax1 = SubplotHost(fig, rect, grid_helper=grid_helper)
        if gs is None:
            ax1 = SubplotHost(fig, 111, grid_helper=grid_helper)
        else:
            ax1 = SubplotHost(fig, gs, grid_helper=grid_helper)



        # make ticklabels of right and top axis visible.
        ax1.axis["right"].major_ticklabels.set_visible(False)
        ax1.axis["top"].major_ticklabels.set_visible(False)
        ax1.axis["bottom"].major_ticklabels.set_visible(True) #Turn off?

        # let right and bottom axis show ticklabels for 1st coordinate (angle)
        ax1.axis["right"].get_helper().nth_coord_ticks=0
        ax1.axis["bottom"].get_helper().nth_coord_ticks=0


        fig.add_subplot(ax1)

        grid_helper = ax1.get_grid_helper()

        # These move the grid
        ax1.set_xlim(xcenter-xwidth, xcenter+xwidth) # moves the origin left-right in ax1
        ax1.set_ylim(ycenter-ywidth, ycenter+ywidth) # moves the origin up-down


        if xlabel is not None: ax1.set_xlabel(xlabel)
        if ylabel is not None: ax1.set_ylabel(ylabel)
        ax1.grid(True, linestyle='-')


        return ax1,tr
Beispiel #7
0
    def __init__(self,
                 rotation,
                 ra_min,
                 ra_max,
                 z_min,
                 z_max,
                 stretch=1,
                 nrows=1,
                 ncols=1,
                 npar=1,
                 width=8.0,
                 aspect=0.8,
                 gridspec=None,
                 blank=True,
                 fontsize=16,
                 legend_fontsize=14,
                 family='serif',
                 style='Times',
                 weight='normal',
                 usetex=False):

        super(ConePlot,
              self).__init__(nrows, ncols, npar, width, aspect, gridspec,
                             blank, fontsize, legend_fontsize, family, style,
                             weight, usetex)

        # Rotate for better orientation:
        rotate = Affine2D().translate(rotation, 0)

        # Scale degree to radians:
        scale = Affine2D().scale(np.pi * stretch / 180, 1)

        transform = rotate + scale + PolarAxes.PolarTransform()

        grid_locator1 = angle_helper.LocatorHMS(4)
        grid_locator2 = MaxNLocator(5)
        tick_formatter1 = angle_helper.FormatterHMS()

        self.grid_helper = floating_axes.GridHelperCurveLinear(
            transform,
            extremes=(ra_min, ra_max, z_min, z_max),
            grid_locator1=grid_locator1,
            grid_locator2=grid_locator2,
            tick_formatter1=tick_formatter1,
            tick_formatter2=None)

        ax = floating_axes.FloatingSubplot(self,
                                           111,
                                           grid_helper=self.grid_helper)

        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('Redshift')
        ax.axis['top'].label.set_text('RA (J2000)')

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

        self.add_subplot(ax)
        self.aux_ax = aux_ax
Beispiel #8
0
def cone(
        ra,
        z,
        scale=0.5,
        orientation='horizontal',
        raaxis='min',
        ralim=None,
        zlim=None,
        hms=False,
        # cosmology=None, lookbtime=False,
        plot=None,
        fig=None,
        subnum=None,
        xlabel=r"$\alpha$",
        ylabel=r"$\mathsf{redshift}$",
        **kwargs):
    """
    Make a wedge plot of RA/Dec vs redshift z, where RA/DEC are in degrees

    Parameters
    ----------
    Input data

    angle : (n, ) array
            RA in degrees
    redshift : (n, ) array

    scale: 0.5

    orientation:
        'horizontal': increasing z along +ve xaxis
        'vertical': increasing z along +ve yaxis
        angle in degrees: increasing z along the tilted axis

    raxis: 'min' | 'mid' | float
        default is 'min'
        RA value along which the cone plot is orientated horizontal
        or vertical

    ralim, zlim: list [ramin, rmax], list [zmin, zmax]
        default is taken from the lower/upper bound of the input data

    scatter: any kwargs compatible with plt.scatter

    hms: show RA labels in units of hours (if True) or degrees (if False)

    lookbtime: True/False

    plot: None
         'scatter' | 'hexbin' etc
    fig: supply figure instance
         default None

    subnum: subplot number e.g. 111, 221 etc
            default None

    xlabel: r"$\alpha$"

    ylabel: r"$\mathsf{redshift}$"

    cosmology: dict
     Uses cosmolopy package to compute look-back time
     default cosmology is {'omega_M_0': 0.3,
                           'omega_lambda_0': 0.7,
                          'h': 0.72}

    kwargs
    ------
    scatter = {'s': 4, 'marker': ','}

    Notes
    -----
        --Decorations that can be done outside the code:
             Draw grids: ax.grid(True, alpha=0.2)
             Set title: ax.set_title('Wedge plot')

        --Look-back time as twin axis to redshift not yet implemented

        --In future plan is to able to put colorbar in the plot too.
          Using cmap option.
    """

    # ------ Extents of ra and z
    if ralim:
        ramin, ramax = ralim
    else:
        ramin, ramax = ra.min(), ra.max()

    if zlim:
        zmin, zmax = zlim
    else:
        zmin, zmax = z.min(), z.max()

    # ----- Scale and Orientation of the wedge
    if orientation == 'horizontal':
        dirn = 0.
    elif orientation == 'vertical':
        dirn = 90.
    else:
        dirn = orientation

    if raaxis == 'min':
        raaxis = ramin
    elif raaxis == 'mid':
        raaxis = 0.5 * (ramin + ramax)

    # Tilt of a cone relative to minimum RA
    tr_rotate = Affine2D().translate(dirn / scale - raaxis, 0.0)

    # Scaling the opening angle
    tr_scale = Affine2D().scale(scale * np.pi / 180., 1.0)

    tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()

    # ---- Grids
    if hms is True:
        grid_locator1 = angle_helper.LocatorHMS(4.0)
        tick_formatter1 = angle_helper.FormatterHMS()
    else:
        grid_locator1 = angle_helper.LocatorDMS(4.0)
        tick_formatter1 = angle_helper.FormatterDMS()

    grid_locator2 = MaxNLocator(10)

    grid_helper = GridHelperCurveLinear(tr,
                                        extremes=(ramin, ramax, zmin, zmax),
                                        grid_locator1=grid_locator1,
                                        grid_locator2=grid_locator2,
                                        tick_formatter1=tick_formatter1,
                                        tick_formatter2=None)

    # Figure properties
    if not fig:
        fig = plt.figure(figsize=(8, 7))
        subnum = 111
    ax = FloatingSubplot(fig, subnum, grid_helper=grid_helper)
    fig.add_subplot(ax)

    # adjust axis
    # Left, right, top represent z, lookbacktime, RA respectively.
    # right axes is for look-back time yet to be coded
    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(ylabel)
    ax.axis["top"].label.set_text(xlabel)

    # create a parasite axes that transData in RA, z
    aux = ax.get_aux_axes(tr)
    aux.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.

    if plot == 'scatter':
        aux.scatter(ra, z, **kwargs)
        # plt.tight_layout()
        # plt.show()
    return ax, aux, fig