Exemplo n.º 1
0
def plot_density(name,targets,xlims=None,nstep=100):
    """
    """
    fig = plt.figure()
    ax = fig.add_subplot(111)

    if xlims is None:
        xmin = Units.convert_to(targets[0].density.rmin,'kpc')
        xmax = Units.convert_to(targets[0].density.rmax,'kpc')
    else:
        xmin = xlims[0]
        xmax = xlims[1]

    if np.isinf(xmax):
        xmax = 10.* Units.convert_to(targets[0].density.rs,'kpc')

    fig = plt.figure()
    ax = fig.add_subplot(111)

    ax.set_xlim((xmin,xmax))
    ax.set_yscale('log')
    ax.set_xlabel('Distance [kpc]')
    ax.set_ylabel(r'Density [GeV / cm$^3$]')
    
    xvals = np.linspace(xmin,xmax,nstep)
    for target in targets:
        density = target.density
        yvals = Units.convert_to(density(Units.convert_from(xvals,'kpc')),'gev_cm3')
        ax.plot(xvals,yvals,color=target.color,label=target.name)
    
    leg = ax.legend(loc="upper right",fontsize=10,ncol=2)

    return fig,ax,leg
Exemplo n.º 2
0
def plot_density(name, targets, xlims=None, nstep=100):
    """Make a plot of the density as a function of distance from
    the target center.

    Parameters
    ----------

    name : str
        Name for the plot

    targets : list
        List of targets to include in the plot

    xlims : tuple
        Range for the x-axis of the plot

    nteps : int
        Number of points to include in the plot

    Returns
    -------

    fig : `matplotlib.Figure`

    ax : `matplotlib.Axes`

    leg : `matplotlib.Legend`

    """
    fig = plt.figure(name)
    ax = fig.add_subplot(111)

    if xlims is None:
        xmin = Units.convert_to(targets[0].density.rmin, 'kpc')
        xmax = Units.convert_to(targets[0].density.rmax, 'kpc')
    else:
        xmin = xlims[0]
        xmax = xlims[1]

    if np.isinf(xmax):
        xmax = 10. * Units.convert_to(targets[0].density.rs, 'kpc')

    fig = plt.figure(name)
    ax = fig.add_subplot(111)

    ax.set_xlim((xmin, xmax))
    ax.set_yscale('log')
    ax.set_xlabel('Distance [kpc]')
    ax.set_ylabel(r'Density [GeV / cm$^3$]')

    xvals = np.linspace(xmin, xmax, nstep)
    for target in targets:
        density = target.density
        yvals = Units.convert_to(density(Units.convert_from(xvals, 'kpc')), 'gev_cm3')
        ax.plot(xvals, yvals, color=target.color, label=target.name)

    leg = ax.legend(loc="upper right", fontsize=10, ncol=2)

    return fig, ax, leg