Example #1
0
def plot_tracks(temperatures_original, luminosities_original,
                temperatures_helium, luminosities_helium):

    x_label = "T [K]"
    y_label = "L [$L_\odot$]"
    figure = single_frame(x_label, y_label, logx=True, logy=True,
                          xsize=14, ysize=10)
    colors = get_distinct(2)
    
    loglog(temperatures_original, luminosities_original, label='progenitor',
           c=colors[0])
    loglog(temperatures_helium, luminosities_helium, label='helium star',
           c=colors[1])
    scatter(temperatures_helium[-1], luminosities_helium[-1], marker='*',
            s=400, c=colors[1])
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(1.0e5, 4000)
    pyplot.ylim(1.0,1.0e5)
    pyplot.legend(loc=4, fontsize=24)

    save_file = 'HertzsprungRussel_HeliumStar.png'
    pyplot.savefig(save_file)
    print '\nSaved figure in file', save_file,'\n'
    pyplot.show()
Example #2
0
    def perform_sanity_checks(self):

        # Let's see what the radius of the gas and dm looks like

        # Donnert (2014), Sec. 3: "The gas profile of one cluster is sampled to a maximal radius $R_{\rm max}$, which is half the box size"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.r,
                        bins=int(numpy.sqrt(self.raw_data.Ngas)),
                        label="Gas")
        amuse_plot.ylabel(r'$N$')
        amuse_plot.xlabel(r'$r$')
        pyplot.legend()

        # Donnert (2014), Sec. 3: "The clusters DM profile is sampled up to infinity"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.r,
                        bins=int(numpy.sqrt(self.raw_data.Ndm)),
                        label="DM")
        pyplot.legend()
        amuse_plot.ylabel(r'$N$')
        amuse_plot.xlabel(r'$r$')

        # Check the velocities of the gas (should only be zero) and of the dm (should follow Hernquist DF)
        for attr in ["vx", "vy", "vz"]:
            # NB, turn into numpy array using value_in method! VectorQuantity has no nonzero method
            v = getattr(self.gas, attr).value_in(units.kms)
            if len(v.nonzero()[0]) != 0:
                print "Error: gas {0} has nonzero values".format(attr)
            else:
                print "Passed: gas {0} only has nonzero values".format(attr)
            v = getattr(self.dm, attr).value_in(units.kms)
            if len(v.nonzero()[0]) == self.raw_data.Ndm:
                print "Passed: dm {0} has no nonzero values".format(attr)
            else:
                print "Error: dm {0} has nonzero values".format(attr)

        # Look at the gas velocity distribution (should only be zero)
        # Donnert (2014), Sec. 3: "The initial velocity of the gas particles is set to zero"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.vx, bins=int(numpy.sqrt(self.raw_data.Ngas)))
        pyplot.xlim(-1, 1)

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.vy, bins=int(numpy.sqrt(self.raw_data.Ngas)))
        pyplot.xlim(-1, 1)

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.gas.vz, bins=int(numpy.sqrt(self.raw_data.Ngas)))
        pyplot.xlim(-1, 1)

        # Look at the dm velocity distribution (should follow Hernquist DF)
        # Donnert (2014), Sec. 3 "The velocity of the DM component is satisfied so the Hernquist DF, equation (5), is satisfied"
        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.vx, bins=int(numpy.sqrt(self.raw_data.Ndm)))

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.vy, bins=int(numpy.sqrt(self.raw_data.Ndm)))

        pyplot.figure(figsize=(9, 9))
        amuse_plot.hist(self.dm.vz, bins=int(numpy.sqrt(self.raw_data.Ndm)))
Example #3
0
def plot_pressure_density_in_thermal_equilibrium(cooling_function,
                                                 heating_function,
                                                 figure_name):
    if not HAS_MATPLOTLIB:
        return
    points_per_decade = 100
    log_n_H = numpy.linspace(-2.0, 3.0, num=points_per_decade * 5 + 1)
    n_H = (units.cm**-3).new_quantity(10**log_n_H)

    logT_equi = numpy.array([
        log_equilibrium_temperature(dens,
                                    cooling_function,
                                    heating_function,
                                    logT_min=-1.0,
                                    logT_max=5.0) for dens in n_H
    ])
    T_equi = 10.0**logT_equi | units.K
    P = (n_H * T_equi).as_quantity_in(units.K * units.cm**-3)

    pyplot.figure(figsize=(12, 10))
    pyplot.gca().set_ylim([1.0e1, 1.0e6])
    loglog(n_H, P)
    xlabel('log($n_H$)')
    ylabel('log(P)')
    pyplot.savefig(figure_name)
    print "\nPlot of pressure vs. density in thermal equilibrium was saved to: ", figure_name
    pyplot.close()
Example #4
0
def plot_tracks(temperatures_original, luminosities_original,
                temperatures_helium, luminosities_helium):

    x_label = "T [K]"
    y_label = "L [$L_\odot$]"
    figure = single_frame(x_label, y_label, logx=True, logy=True,
                          xsize=14, ysize=10)
    colors = get_distinct(2)
    
    loglog(temperatures_original, luminosities_original, label='progenitor',
           c=colors[0])
    loglog(temperatures_helium, luminosities_helium, label='helium star',
           c=colors[1])
    scatter(temperatures_helium[-1], luminosities_helium[-1], marker='*',
            s=400, c=colors[1])
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(1.0e5, 4000)
    pyplot.ylim(1.0,1.0e5)
    pyplot.legend(loc=4, fontsize=24)

    save_file = 'HertzsprungRussel_HeliumStar.png'
    pyplot.savefig(save_file)
    print('\nSaved figure in file', save_file,'\n')
    pyplot.show()
Example #5
0
def evolve_and_plot_internal_energy(u_0,
                                    dt,
                                    n_H,
                                    T_0=None,
                                    du_dt_adiabatic=zero,
                                    figure_name=None):
    if not T_0 is None:
        u_0 = u_from_T(T_0)
    function = lambda u: du_dt_adiabatic * u / u_0 + (
        gerritsen_heating_function() - n_H * my_cooling_function(T_from_u(u)
                                                                 )) / global_mu
    time, u = integrate_ode_for_plot(function, u_0, dt)

    if figure_name and HAS_MATPLOTLIB:
        pyplot.figure(figsize=(12, 10))
        pyplot.subplot(2, 1, 1)
        plot(time, u.as_quantity_in(units.erg / units.g))
        xlabel('time')
        ylabel('internal energy')

        pyplot.subplot(2, 1, 2)
        plot(time, T_from_u(u))
        xlabel('time')
        ylabel('T')
        pyplot.savefig(figure_name)
        print "\nPlot of integrated ODE was saved to: ", figure_name
        pyplot.close()
    else:
        print u[-1]
Example #6
0
def plot_results(stars, time):
    mass_loss = stars.zams_mass - stars.mass

    x = stars.x.in_(units.parsec)
    y = stars.y.in_(units.parsec)

    pyplot.figure(figsize=(8,8))
    aplot.plot(x, y, "*")

    for x, y, mass_loss in zip(x.number, y.number, mass_loss):
        pyplot.annotate("%0.2f"%abs(mass_loss.number), xy=(x,y+2),
            horizontalalignment='center', verticalalignment='bottom')

    pyplot.axis('equal')
    pyplot.xlim([-60, 60])
    pyplot.ylim([-60, 60])
    aplot.xlabel("x")
    aplot.ylabel("y")
    pyplot.title("time = " + str(time))

    if not os.path.exists("plots"):
        os.mkdir("plots")

    name = "plots/plot_{0:=05}.png".format(int(time.value_in(units.Myr)))
    print("creating", name)
    pyplot.savefig(name)
    pyplot.close()
Example #7
0
def make_effective_iso_potential_plot(gravity_code):
    omega = (constants.G * gravity_code.particles.total_mass() / (1.0|units.AU**3)).sqrt()
    center_of_mass = gravity_code.particles.center_of_mass()[:2]
    pyplot.rcParams.update({'font.size': 30})
    figure = pyplot.figure(figsize = (12, 12))
    ax = pyplot.gca()
    ax.get_yaxis().get_major_formatter().set_useOffset(False)
    ax.minorticks_on() 
    
    current_axes = pyplot.subplot(1, 1, 1)
    current_axes.set_aspect("equal", adjustable = "box")
    lim = 1.7
    effective_iso_potential_plot(gravity_code, 
                                 omega,
                                 xlim = [-lim, lim] | units.AU,
                                 ylim = [-lim, lim] | units.AU,
                                 center_of_rotation = center_of_mass,
                                 fraction_screen_filled=0.8)
    xlabel('x')
    ylabel('y')
    pyplot.text(0.6, -0.06, "$L_1$")
    pyplot.text(1.35, -0.06, "$L_2$")
    pyplot.text(-0.99, -0.06, "$L_3$")
    pyplot.text(0.40, 0.82, "$L_4$")
    pyplot.text(0.40, -0.92, "$L_5$")
#    pyplot.show()
    pyplot.savefig("lagrange_points")
Example #8
0
def make_movie(input_filename, output_filename):
    cluster, gas = read_set_from_file(input_filename, 'amuse', 
            names=("cluster", "gas"))
    lim = abs(next(cluster.history).position).max()
    
    fig = pyplot.figure(figsize=[10,10])

    artists = []
    for cl, gas in zip(cluster.history, gas.history):
        print "Creating frame at time", cl.get_timestamp()
        points = aplot.scatter(cl.x, cl.y, c='black')
        gas_points = aplot.scatter(gas.x, gas.y, s=100, c='b', 
                edgecolors='none', alpha=0.3, rasterized=True)

        time_label = "t = {:.2f} Myr".format(
                cl.get_timestamp().value_in(units.Myr))
        text = aplot.text(-4./5.*lim, 4./5.*lim, time_label)
        aplot.xlabel("X")
        aplot.ylabel("Y")
        pyplot.axis('equal')
        aplot.xlim(-lim, lim)
        aplot.ylim(-lim, lim)
        pyplot.savefig("plots/test."+str(cl.get_timestamp().value_in(units.Myr))+".png")
        pyplot.close()
                

        artists.append((points, gas_points, text))
Example #9
0
def plot_results(stars, time):
    mass_loss = stars.zams_mass - stars.mass

    x = stars.x.in_(units.parsec)
    y = stars.y.in_(units.parsec)

    pyplot.figure(figsize=(8, 8))
    aplot.plot(x, y, "*")

    for x, y, mass_loss in zip(x.number, y.number, mass_loss):
        pyplot.annotate(
            "%0.2f" % abs(mass_loss.number),
            xy=(x, y + 2),
            horizontalalignment='center',
            verticalalignment='bottom',
        )

    pyplot.axis('equal')
    pyplot.xlim([-60, 60])
    pyplot.ylim([-60, 60])
    aplot.xlabel("x")
    aplot.ylabel("y")
    pyplot.title("time = " + str(time))

    if not os.path.exists("plots"):
        os.mkdir("plots")

    name = "plots/plot_{0:=05}.png".format(int(time.value_in(units.Myr)))
    print("creating", name)
    pyplot.savefig(name)
    pyplot.close()
Example #10
0
def main(filename):
    pyplot.figure(figsize=(12, 12))
    particles = read_set_from_file(filename, "amuse")
    for si in particles.history:
        scatter(si.x, si.y, s=100)
    xlabel("x")
    ylabel("y")
    pyplot.show()
Example #11
0
def main(filename):
    pyplot.figure(figsize=(12,12))
    particles = read_set_from_file(filename, "hdf5")
    for si in particles.history:
        scatter(si.x, si.y, s=100)
    xlabel("x")
    ylabel("y")
    pyplot.show()
Example #12
0
    def dm_rvir_gas_sph_subplot(self):
        fig = pyplot.figure(figsize=(20, 10))
        ax_dm = fig.add_subplot(121, aspect='equal')
        ax_gas = fig.add_subplot(122, aspect='equal',
            sharex=ax_dm, sharey=ax_dm)

        # plot dark matter
        center_of_mass = self.dm.center_of_mass()
        virial_radius = self.dm.virial_radius().as_quantity_in(units.kpc)
        innersphere = self.dm.select(lambda r: (center_of_mass-r).length()<virial_radius,["position"])
        outersphere = self.dm.select(lambda r: (center_of_mass-r).length()>= virial_radius,["position"])
        pyplot.gcf().sca(ax_dm)
        x = outersphere.x.as_quantity_in(units.kpc)
        y = outersphere.y.as_quantity_in(units.kpc)
        scatter(x, y, c='red', edgecolor='red', label=r'$r \geq r_{\rm vir}$')
        x = innersphere.x.as_quantity_in(units.kpc)
        y = innersphere.y.as_quantity_in(units.kpc)
        scatter(x, y, c='green', edgecolor='green', label=r'$r < r_{\rm vir}$')
        xlabel(r'$x$')
        ylabel(r'$y$')
        pyplot.legend()

        # plot gas as sph plot

        # Adjusted code from amuse.plot.sph_particles_plot
        pyplot.gcf().sca(ax_gas)
        min_size = 100
        max_size = 10000
        alpha = 0.1
        x = self.gas.x.as_quantity_in(units.kpc)
        y = self.gas.y.as_quantity_in(units.kpc)
        z = self.gas.z.as_quantity_in(units.kpc)
        z, x, y, us, h_smooths = z.sorted_with(x, y, self.gas.u, self.gas.h_smooth)
        u_min, u_max = min(us), max(us)

        log_u = numpy.log((us / u_min)) / numpy.log((u_max / u_min))
        clipped_log_u = numpy.minimum(numpy.ones_like(log_u), numpy.maximum(numpy.zeros_like(log_u), log_u))

        red = 1.0 - clipped_log_u**4
        blue = clipped_log_u**4
        green = numpy.minimum(red, blue)

        colors = numpy.transpose(numpy.array([red, green, blue]))
        n_pixels = pyplot.gcf().get_dpi() * pyplot.gcf().get_size_inches()

        ax_gas.set_axis_bgcolor('#101010')
        ax_gas.set_aspect("equal", adjustable="datalim")
        phys_to_pix2 = n_pixels[0]*n_pixels[1] / ((max(x)-min(x))**2 + (max(y)-min(y))**2)
        sizes = numpy.minimum(numpy.maximum((h_smooths**2 * phys_to_pix2), min_size), max_size)

        scatter(x, y, color=colors, s=sizes, edgecolors="none", alpha=alpha)
        xlabel(r'$x$')
        ylabel(r'$y$')

        xlim(-2.*virial_radius, 2*virial_radius)
        ylim(-2.*virial_radius, 2*virial_radius)
        pyplot.tight_layout()
        pyplot.show()
Example #13
0
def make_plot(radius_profile, brunt_profile, mass, age):
    figure = pyplot.figure()
    semilogy(radius_profile, -brunt_profile, 'g-', label = r'convective, $N^2$ < 0')
    semilogy(radius_profile, brunt_profile, 'r-', label = r'radiative, $N^2$ > 0')
    xlabel('Radius')
    ylabel(r'$\|N^2\|$')
    pyplot.title('Brunt-Vaisala frequency squared of a {0} star at {1}'.format(mass, age))
    pyplot.legend(loc=3)
    pyplot.show()   
Example #14
0
def main(N=10): 
    figure(figsize=(5,5))
    bodies = new_plummer_model(N)
    scatter(bodies.x, bodies.y)
    xlim(-1, 1)
    ylim(-1, 1)
    xlabel("X")
    ylabel("Y")
    show()
def main(N=10):
    figure(figsize=(5, 5))
    bodies = new_plummer_model(N)
    scatter(bodies.x, bodies.y)
    xlim(-1, 1)
    ylim(-1, 1)
    xlabel("X")
    ylabel("Y")
    show()
Example #16
0
def plot_track(temperature_at_time, luminosity_at_time):
    pyplot.figure(figsize=(8, 6))
    pyplot.title('Hertzsprung-Russell diagram', fontsize=12)

    loglog(temperature_at_time, luminosity_at_time)
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(pyplot.xlim()[::-1])
    pyplot.ylim(.1, 1.e4)
    pyplot.show()
Example #17
0
def plot_track(temperature_at_time, luminosity_at_time):
    pyplot.figure(figsize=(8, 6))
    pyplot.title('Hertzsprung-Russell diagram', fontsize=12)

    loglog(temperature_at_time, luminosity_at_time)
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(pyplot.xlim()[::-1])
    pyplot.ylim(.1, 1.e4)
    pyplot.show()
Example #18
0
def thermal_energy_plot(time, E_therm, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize = (5, 5))
    plot(time, E_therm.as_quantity_in(units.erg), label='E_therm')
    xlabel('Time')
    ylabel('Energy')
    pyplot.legend(loc=3)
    pyplot.savefig(figname)
    print "\nPlot of thermal energy evolution was saved to: ", figname
    pyplot.close()
Example #19
0
def plot_tracks(temperature1, luminosity1, temperature2, luminosity2):
    from matplotlib import pyplot
    from amuse.plot import loglog, xlabel, ylabel
    pyplot.figure(figsize = (8, 6))
    pyplot.title('Hertzsprung-Russell diagram', fontsize=12)
    loglog(temperature1, luminosity1)
    loglog(temperature2, luminosity2)
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(pyplot.xlim()[::-1])
    pyplot.show()
Example #20
0
def thermal_energy_plot(time, E_therm, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize=(5, 5))
    plot(time, E_therm.as_quantity_in(units.erg), label='E_therm')
    xlabel('Time')
    ylabel('Energy')
    pyplot.legend(loc=3)
    pyplot.savefig(figname)
    print("\nPlot of thermal energy evolution was saved to: ", figname)
    pyplot.close()
def plot_tracks(temperatures_original, luminosities_original, temperatures_helium, luminosities_helium):
    pyplot.figure(figsize = (8, 6))
    pyplot.title('Hertzsprung-Russell diagram', fontsize=12)

    loglog(temperatures_original, luminosities_original, label='progenitor')
    loglog(temperatures_helium, luminosities_helium, label='helium star')
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(pyplot.xlim()[::-1])
    pyplot.ylim(1.0,1.0e5)
    pyplot.legend(loc=3)
    pyplot.show()
Example #22
0
def plot_tracks(temperatures_original, luminosities_original, temperatures_helium, luminosities_helium):
    pyplot.figure(figsize = (8, 6))
    pyplot.title('Hertzsprung-Russell diagram', fontsize=12)
    
    loglog(temperatures_original, luminosities_original, label='progenitor')
    loglog(temperatures_helium, luminosities_helium, label='helium star')
    xlabel('Effective Temperature')
    ylabel('Luminosity')
    pyplot.xlim(pyplot.xlim()[::-1])
    pyplot.ylim(1.0,1.0e5)
    pyplot.legend(loc=3)
    pyplot.show()
Example #23
0
def energy_evolution_plot(time, kinetic, potential, thermal, figname = "energy_evolution.png"):
    time.prepend(0.0 | units.day)
    pyplot.figure(figsize = (5, 5))
    plot(time, kinetic, label='K')
    plot(time, potential, label='U')
    plot(time, thermal, label='Q')
    plot(time, kinetic + potential + thermal, label='E')
    xlabel('Time')
    ylabel('Energy')
    pyplot.legend(prop={'size':"x-small"}, loc=4)
    pyplot.savefig(figname)
    pyplot.close()
Example #24
0
def energy_evolution_plot(time, kinetic, potential, thermal, figname = "energy_evolution.png"):
    time.prepend(0.0 | units.day)
    pyplot.figure(figsize = (5, 5))
    plot(time, kinetic, label='K')
    plot(time, potential, label='U')
    plot(time, thermal, label='Q')
    plot(time, kinetic + potential + thermal, label='E')
    xlabel('Time')
    ylabel('Energy')
    pyplot.legend(prop={'size':"x-small"}, loc=4)
    pyplot.savefig(figname)
    pyplot.close()
Example #25
0
    def plot_densities(self):
        print "Plotting x-density as function of time"

        if not os.path.exists('out/{0}/plots/density'.format(self.timestamp)):
            os.mkdir('out/{0}/plots/density'.format(self.timestamp))

        density_gasA_list = [] | (units.MSun / units.Mpc**3)
        density_dmA_list = [] | (units.MSun / units.Mpc**3)
        density_gasB_list = [] | (units.MSun / units.Mpc**3)
        density_dmB_list = [] | (units.MSun / units.Mpc**3)
        time_list = [] | units.Gyr

        paths = sorted(glob.glob('out/{0}/data/gasA_*'.format(self.timestamp)),
                       key=os.path.getmtime)
        tot = len(paths) - 1
        for i, path in enumerate(paths):
            time = path[28:-6]  # fix due to round error when storing the data.
            print_progressbar(i, tot)
            gasA = read_set_from_file(
                "out/{0}/data/gasA_{1}.amuse".format(self.timestamp, time),
                "amuse")
            dmA = read_set_from_file(
                "out/{0}/data/dmA_{1}.amuse".format(self.timestamp, time),
                "amuse")
            gasB = read_set_from_file(
                "out/{0}/data/gasB_{1}.amuse".format(self.timestamp, time),
                "amuse")
            dmB = read_set_from_file(
                "out/{0}/data/dmB_{1}.amuse".format(self.timestamp, time),
                "amuse")

            density_gasA = gasA.mass / (4. / 3 * numpy.pi * gasA.h_smooth**3)
            density_dmA = dmA.mass / (4. / 3 * numpy.pi * dmA.radius**3)
            density_gasB = gasB.mass / (4. / 3 * numpy.pi * gasB.h_smooth**3)
            density_dmB = dmA.mass / (4. / 3 * numpy.pi * dmA.radius**3)

            fig = pyplot.figure(figsize=(12, 10), dpi=50)
            plot(gasA.x, density_gasA, label="gasA", c="r", ls="solid")
            plot(dmA.x, density_dmA, label="dmA", c="r", ls="dashed")
            plot(gasB.x, density_gasB, label="gasB", c="g", ls="solid")
            plot(dmB.x, density_dmB, label="dmB", c="g", ls="dashed")
            xlabel("x")
            ylabel("Density")
            pyplot.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
            pyplot.show()
            pyplot.savefig('out/{0}/plots/density/density_{1}'.format(
                self.timestamp, time),
                           dpi=50)
            pyplot.close()

            if i > 10:
                break
        print
Example #26
0
def orbit_plot(distance, mass, time):
    figure = pyplot.figure(figsize=(6, 10), dpi=100)
    subplot = figure.add_subplot(2, 1, 1)
    plot(time, distance)
    xlabel('t')
    ylabel('separation')
    pyplot.margins(0.05)
    subplot = figure.add_subplot(2, 1, 2)
    plot(time, ((mass - mass[0]) / mass[0]) * 100.0)
    xlabel('t')
    ylabel('mass')
    pyplot.margins(0.05)
    pyplot.show()
Example #27
0
def energy_evolution_plot(time, kinetic, potential, thermal, figname="energy_evolution.png"):
    native_plot.subplot(211)
    plot(time, kinetic, label='K')
    plot(time, potential, label='U')
    plot(time, thermal, label='Q')
    plot(time, kinetic + potential + thermal, label='E')
    xlabel('Time')
    ylabel('Energy')
    native_plot.legend(prop={'size':"x-small"}, loc=4)
    native_plot.subplot(212)
    plot(time, thermal, label='Q')
    native_plot.savefig(figname)
    native_plot.clf()
Example #28
0
def composition_comparison_plot(radii_SE, comp_SE, radii_SPH, comp_SPH, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize = (7, 5))
    plot(radii_SE.as_quantity_in(units.RSun), comp_SE, 
        label='stellar evolution model')
    plot(radii_SPH, comp_SPH, 'go', label='SPH model')
    xlabel('radius')
    ylabel('mass fraction')
    pyplot.legend()
    pyplot.savefig(figname)
    print "\nPlot of composition profiles was saved to: ", figname
    pyplot.close()
Example #29
0
def energy_evolution_plot(time, kinetic, potential, thermal, figname="energy_evolution.png"):
    native_plot.subplot(211)
    plot(time, kinetic, label='K')
    plot(time, potential, label='U')
    plot(time, thermal, label='Q')
    plot(time, kinetic + potential + thermal, label='E')
    xlabel('Time')
    ylabel('Energy')
    native_plot.legend(prop={'size':"x-small"}, loc=4)
    native_plot.subplot(212)
    plot(time, thermal, label='Q')
    native_plot.savefig(figname)
    native_plot.clf()
Example #30
0
def orbit_plot(distance, mass, time):
    figure = pyplot.figure(figsize=(6, 10), dpi=100)
    subplot = figure.add_subplot(2, 1, 1)
    plot(time, distance)
    xlabel('t')
    ylabel('separation')
    pyplot.margins(0.05)
    subplot = figure.add_subplot(2, 1, 2)
    plot(time, ((mass - mass[0]) / mass[0]) * 100.0)
    xlabel('t')
    ylabel('mass')
    pyplot.margins(0.05)
    pyplot.show()
Example #31
0
def internal_energy_comparison_plot(radii_SE, u_SE, radii_SPH, u_SPH, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize = (7, 5))
    semilogy(radii_SE.as_quantity_in(units.RSun), u_SE, 
        label='stellar evolution model')
    semilogy(radii_SPH, u_SPH, 'go', label='SPH model')
    xlabel('radius')
    ylabel('internal energy')
    pyplot.legend()
    pyplot.savefig(figname)
    print "\nPlot of internal energy profiles was saved to: ", figname
    pyplot.close()
Example #32
0
def internal_energy_comparison_plot(radii_SE, u_SE, radii_SPH, u_SPH, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize=(7, 5))
    semilogy(radii_SE.as_quantity_in(units.RSun), u_SE,
             label='stellar evolution model')
    semilogy(radii_SPH, u_SPH, 'go', label='SPH model')
    xlabel('radius')
    ylabel('internal energy')
    pyplot.legend()
    pyplot.savefig(figname)
    print("\nPlot of internal energy profiles was saved to: ", figname)
    pyplot.close()
Example #33
0
def plot_cooling_function(cooling_function, figure_name):
    points_per_decade = 20
    logT = numpy.linspace(1.0, 8.0, num=points_per_decade * 7 + 1)
    T = units.K.new_quantity(10**logT)

    pyplot.figure(figsize=(12, 10))
    pyplot.gca().set_ylim([1.0e-28, 1.0e-21])
    loglog(T, cooling_function(T))
    xlabel('log(T)')
    ylabel('log($\Lambda$)')
    pyplot.savefig(figure_name)
    print "\nPlot of cooling function was saved to: ", figure_name
    pyplot.close()
def make_plots(Ncl, Rcl, t_end):
    """ Not finished """
    try:
        import matplotlib
        matplotlib.use("Agg")
        from matplotlib import pyplot
    except ImportError:
        print "Unable to produce plots: couldn't find matplotlib"
    else:
        fig = pyplot.figure(figsize=[10, 10])
        for data in ["hybrid", "tree", "direct"]
            print "Generating plot data of {0} run".format(data)
            data_file = "CA_Exam_TLRH_{0}.amuse".format(data)

            stars_below_cut, stars_above_cut =\
            read_set_from_file(data_file, 'amuse',
                               names=("stars_below_cut", "stars_below_cut"))

            lim = abs(next(stars_below_cut.history).position).max()

            if data == "hybrid":
                pass
                # dashed curve
                # points = aplot.scatter(dE, time, c='orange',
                #               label='Hybrid')


            if data == "direct":
                pass
                # dotted curve
                # points = aplot.scatter(dE, time, c='red',
                #               label='Direct')

            if data == "tree":
                pass
                # solid curve
                # points = aplot.scatter(dE, time, c='green',
                #               label='Tree')

        aplot.xlabel("Time")
        aplot.ylabel("Relative Energy Error")
        pyplot.axis('equal')
        aplot.xlim(-lim, lim)
        aplot.ylim(-lim, lim)
        pyplot.legend()
        pyplot.title(r'Cluster with $N=${0}, $r=${1}'
                     .format(Ncl, Rcl ) +
                     r', evolved until $t_{\rm end}$={0}'
                     .format(t_end))
        pyplot.savefig("out.png")
        pyplot.close()
Example #35
0
def orbit_ecc_plot(eccentricity_in,eccentricity_out,time):
    figure = pyplot.figure(figsize = (10, 6), dpi = 100)
    subplot = figure.add_subplot(2, 1, 1)
    plot(time,eccentricity_in)
    xlabel('t')
    ylabel('e$_\mathrm{binary}$')
    
    subplot = figure.add_subplot(2, 1, 2)
    plot(time,eccentricity_out )  
    xlabel('t')
    ylabel('e$_\mathrm{giant}$')
    pyplot.minorticks_on()
    pyplot.savefig("eccentricity_evolution.png")
    pyplot.close()
Example #36
0
def orbit_parameters_plot(semi_major_in,semi_major_out, time, par_symbol="a", par_name="semimajor_axis"):
    figure = pyplot.figure(figsize = (10, 6), dpi = 100)
    subplot = figure.add_subplot(2, 1, 1)
    plot(time,semi_major_in )
    xlabel('t')
    ylabel('$'+par_symbol+'_\mathrm{binary}$')
    
    subplot = figure.add_subplot(2, 1, 2)
    plot(time,semi_major_out )
    xlabel('t')
    ylabel('$'+par_symbol+'_\mathrm{giant}$')
    pyplot.minorticks_on()
    pyplot.savefig(par_name+"_evolution.png")
    pyplot.close()
Example #37
0
def energy_plot(time, E_kin, E_pot, E_therm, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize=(5, 5))
    plot(time, E_kin.as_quantity_in(units.erg), label='E_kin')
    plot(time, E_pot, label='E_pot')
    plot(time, E_therm, label='E_therm')
    plot(time, E_kin + E_pot + E_therm, label='E_total')
    xlabel('Time')
    ylabel('Energy')
    pyplot.legend(loc=3)
    pyplot.savefig(figname)
    print "\nPlot of energy evolution was saved to: ", figname
    pyplot.close()
Example #38
0
def energy_plot(time, E_kin, E_pot, E_therm, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize=(5, 5))
    plot(time, E_kin.as_quantity_in(units.erg), label="E_kin")
    plot(time, E_pot, label="E_pot")
    plot(time, E_therm, label="E_therm")
    plot(time, E_kin + E_pot + E_therm, label="E_total")
    xlabel("Time")
    ylabel("Energy")
    pyplot.legend(loc=3)
    pyplot.savefig(figname)
    print "\nPlot of energy evolution was saved to: ", figname
    pyplot.close()
Example #39
0
def composition_comparison_plot(
        radii_SE, comp_SE, radii_SPH, comp_SPH, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize=(7, 5))
    plot(radii_SE.as_quantity_in(units.RSun), comp_SE,
         label='stellar evolution model')
    plot(radii_SPH, comp_SPH, 'go', label='SPH model')
    xlabel('radius')
    ylabel('mass fraction')
    pyplot.legend()
    pyplot.savefig(figname)
    print("\nPlot of composition profiles was saved to: ", figname)
    pyplot.close()
Example #40
0
def orbit_parameters_plot(semi_major_in,semi_major_out, time, par_symbol="a", par_name="semimajor_axis"):
    figure = pyplot.figure(figsize = (10, 6), dpi = 100)
    subplot = figure.add_subplot(2, 1, 1)
    plot(time,semi_major_in )
    xlabel('t')
    ylabel('$'+par_symbol+'_\mathrm{binary}$')
    
    subplot = figure.add_subplot(2, 1, 2)
    plot(time,semi_major_out )
    xlabel('t')
    ylabel('$'+par_symbol+'_\mathrm{giant}$')
    pyplot.minorticks_on()
    pyplot.savefig(par_name+"_evolution.png")
    pyplot.close()
Example #41
0
def orbit_ecc_plot(eccentricity_in,eccentricity_out,time):
    figure = pyplot.figure(figsize = (10, 6), dpi = 100)
    subplot = figure.add_subplot(2, 1, 1)
    plot(time,eccentricity_in)
    xlabel('t')
    ylabel('e$_\mathrm{binary}$')
    
    subplot = figure.add_subplot(2, 1, 2)
    plot(time,eccentricity_out )  
    xlabel('t')
    ylabel('e$_\mathrm{giant}$')
    pyplot.minorticks_on()
    pyplot.savefig("eccentricity_evolution.png")
    pyplot.close()
Example #42
0
def energy_plot(time, E_kin_list, E_pot_list, E_therm_list, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize = (5, 5))
    for i, (E_kin, E_pot, E_therm) in enumerate(zip(E_kin_list, E_pot_list, E_therm_list)):
        plot(time, E_kin.as_quantity_in(units.erg), label=labels[i][0])
        plot(time, E_pot, label=labels[i][1])
        plot(time, E_therm, label=labels[i][2])
        plot(time, E_kin+E_pot+E_therm, label=labels[i][3])
    xlabel('Time')
    ylabel('Energy')
    pyplot.legend(prop={'size':"x-small"}, loc=3)
    pyplot.savefig(figname)
    print "\nPlot of energy evolution was saved to: ", figname
    pyplot.close()
Example #43
0
def energy_plot(time, E_kin_list, E_pot_list, E_therm_list, figname):
    if not HAS_MATPLOTLIB:
        return
    pyplot.figure(figsize=(5, 5))
    for i, (E_kin, E_pot,
            E_therm) in enumerate(zip(E_kin_list, E_pot_list, E_therm_list)):
        plot(time, E_kin.as_quantity_in(units.erg), label=labels[i][0])
        plot(time, E_pot, label=labels[i][1])
        plot(time, E_therm, label=labels[i][2])
        plot(time, E_kin + E_pot + E_therm, label=labels[i][3])
    xlabel('Time')
    ylabel('Energy')
    pyplot.legend(prop={'size': "x-small"}, loc=3)
    pyplot.savefig(figname)
    print "\nPlot of energy evolution was saved to: ", figname
    pyplot.close()
Example #44
0
def make_plot(radius_profile, brunt_profile, mass, age):
    figure = pyplot.figure()
    semilogy(radius_profile,
             -brunt_profile,
             'g-',
             label=r'convective, $N^2$ < 0')
    semilogy(radius_profile,
             brunt_profile,
             'r-',
             label=r'radiative, $N^2$ > 0')
    xlabel('Radius')
    ylabel(r'$\|N^2\|$')
    pyplot.title('Brunt-Vaisala frequency squared of a {0} star at {1}'.format(
        mass, age))
    pyplot.legend(loc=3)
    pyplot.show()
def plot_cluster(stars, filename, t, rcl):
    filename += ".png"
    #lim = 10*stars.center_of_mass().length().value_in(stars.x.unit)
    lim = (R * 2).value_in(units.m)
    m = 1 + 3.0*stars.mass/min(stars.mass)

    pyplot.title("Cluster at distance "+str(R)+" with cluster radius "+
            str(rcl)+"\nat t="+str(t))

    scatter(stars.x, stars.y)  # s size (in point^2)
    xlabel("X")
    ylabel("Y")
    pyplot.xlim(-lim, lim)
    pyplot.ylim(-lim, lim)
    pyplot.savefig(filename)
    pyplot.clf()
Example #46
0
def plot_cluster(stars, filename, t, rcl, V):
    filename += ".png"
    #lim = 10*stars.center_of_mass().length().value_in(stars.x.unit)
    lim = (R * 2).value_in(units.m)
    m = 1 + 3.0 * stars.mass / min(stars.mass)

    pyplot.title("Cluster at distance " + str(R) + " with cluster radius " +
                 str(rcl) + "\nvelocity " + str(V) + "\nat t=" + str(t))

    scatter(stars.x, stars.y)  # s size (in point^2)
    xlabel("X")
    ylabel("Y")
    pyplot.xlim(-lim, lim)
    pyplot.ylim(-lim, lim)
    pyplot.savefig(filename)
    pyplot.clf()
Example #47
0
def main(filename, lim):
    pyplot.ion()
    particles = read_set_from_file(filename, "hdf5") 
    if lim<=zero:
        lim = max(particles.x).value_in(lim.unit)
    time = 0
    for si in particles.history:
        pyplot.title("Cluster at t="+str(time))
        scatter(si.x.as_quantity_in(lim.unit), si.y.as_quantity_in(lim.unit))
        xlabel("X")
        ylabel("Y")
        if lim>zero:
            pyplot.xlim(-lim.value_in(lim.unit), lim.value_in(lim.unit))
            pyplot.ylim(-lim.value_in(lim.unit), lim.value_in(lim.unit))
        pyplot.draw()
        pyplot.cla()
    pyplot.show()
Example #48
0
def plot(x, y):
    
    pyplot.figure(figsize=(8,8))

    colormap = ['yellow', 'green', 'blue']	# specific to a 3-body plot
    size = [40, 20, 20]
    edgecolor = ['orange', 'green', 'blue']
    
    for si in particles.history:
        scatter(si.x, si.y, c=colormap, s=size, edgecolor=edgecolor)
    xlabel("x")
    ylabel("y")

    save_file = 'plot_gravity.png'
    pyplot.savefig(save_file)
    print('\nSaved figure in file', save_file,'\n')
    pyplot.show()
Example #49
0
    def test2(self):
        """ Test a basic plot with and without units and labels"""
        if not HAS_MATPLOTLIB:
            return self.skip()
        pyplot.clf()

        x = numpy.linspace(0, 100, 100) | units.yr
        y = numpy.linspace(0, 200, 100)

        aplot.plot(x, y)
        self.assertEquals("[yr]", self.xaxis().get_label_text())
        self.assertEquals("", self.yaxis().get_label_text())

        aplot.xlabel("time")
        aplot.ylabel("radius")
        self.assertEquals("time [yr]", self.xaxis().get_label_text())
        self.assertEquals("radius ", self.yaxis().get_label_text())
Example #50
0
    def test2(self):
        """ Test a basic plot with and without units and labels"""
        if not HAS_MATPLOTLIB:
            return self.skip()
        pyplot.clf()

        x = numpy.linspace(0, 100, 100) | units.yr
        y = numpy.linspace(0, 200, 100)

        aplot.plot(x, y)
        self.assertEquals("[yr]", self.xaxis().get_label_text())
        self.assertEquals("", self.yaxis().get_label_text())

        aplot.xlabel("time")
        aplot.ylabel("radius")
        self.assertEquals("time [yr]", self.xaxis().get_label_text())
        self.assertEquals("radius ", self.yaxis().get_label_text())
Example #51
0
def plot(x, y):
    
    pyplot.figure(figsize=(8,8))

    colormap = ['yellow', 'green', 'blue']	# specific to a 3-body plot
    size = [40, 20, 20]
    edgecolor = ['orange', 'green', 'blue']
    
    for si in particles.history:
        scatter(si.x, si.y, c=colormap, s=size, edgecolor=edgecolor)
    xlabel("x")
    ylabel("y")

    save_file = 'plot_gravity.png'
    pyplot.savefig(save_file)
    print '\nSaved figure in file', save_file,'\n'
    pyplot.show()
    def __init__(self):
        self.merger = ClusterMerger()

        timesteps = VectorQuantity.arange(0 | units.Myr, 1 | units.Gyr, 50 | units.Myr)
        tot = len(timesteps)
        end_time = timesteps[-1]

        print "Starting Simulation :-)"
        print "Generating plots on the fly :-)"

        gasA_vel_list = [] | (units.km/units.s)
        dmA_vel_list = [] | (units.km/units.s)
        gasB_vel_list = [] | (units.km/units.s)
        dmB_vel_list = [] | (units.km/units.s)
        time_list = [] | units.Gyr
        for i, time in enumerate(timesteps):
            print_progressbar(i, tot)
            self.merger.code.evolve_model(time)
            self.merger.dm_gas_sph_subplot(i)
            gasA_vel_list.append(self.merger.gasA.center_of_mass_velocity())
            dmA_vel_list.append(self.merger.dmA.center_of_mass_velocity())
            gasB_vel_list.append(self.merger.gasB.center_of_mass_velocity())
            dmB_vel_list.append(self.merger.dmB.center_of_mass_velocity())
            time_list.append(time)
            write_set_to_file(self.merger.code.particles,
                'out/{0}/data/cluster_{1}.amuse'.format(self.merger.timestamp, i),
                "amuse")

        print "Plotting velocity as function of time"
        fig = pyplot.figure(figsize=(12, 10), dpi=50)
        plot(time_list.number, gasA_vel_list.number, label="gasA", c='r', ls='solid')
        plot(time_list.number, dmA_vel_list.number, label="dmA", c='r', ls='dashed')
        plot(time_list.number, gasB_vel_list.number, label="gasB", c='g', ls='solid')
        plot(time_list.number, dmB_vel_list.number, label="dmB", c='g', ls='dashed')
        xlabel("Time")
        ylabel("Velocity")
        pyplot.legend()
        pyplot.show()

        print "Generating gif :-)"
        self.merger.create_gif()

        print "Stopping the code. End of pipeline :-)"
        self.merger.code.stop()
Example #53
0
def main(filename = "nbody.hdf5", lim=3):
    pyplot.ion()
    storage = store.StoreHDF(filename,"r")
    stars = storage.load()
#    lim = 4*stars.center_of_mass().length().value_in(stars.x.unit)
    lim = 2*max(max(stars.x).value_in(stars.x.unit),  stars.center_of_mass().length().value_in(stars.x.unit))
    m =  1 + 3.0*stars.mass/min(stars.mass)
    for si in stars.history:
        time = si.get_timestamp()
        pyplot.title("Cluster at t="+str(time))
        print "time = ", time
        scatter(si.x, si.y, s=m)
        xlabel("X")
        ylabel("Y")
        pyplot.xlim(-lim, lim)
        pyplot.ylim(-lim, lim)
        pyplot.draw()
        pyplot.cla()
    pyplot.show()
Example #54
0
def subplot(potential, orbits, codes, fit_orbit, labels):
    hor, vert = labels
    X = numpy.linspace(-160, 160, 100) | units.parsec
    Y = numpy.linspace(-160, 160, 100) | units.parsec
    X, Y = quantities.meshgrid(X, Y)

    if labels == 'xy':
        pot_args = [X, Y, 0 | units.parsec]
        fit_horizontal = fit_orbit[0]
        fit_vertical = fit_orbit[1]
    elif labels == 'xz':
        pot_args = [X, 0 | units.parsec, Y]
        fit_horizontal = fit_orbit[0]
        fit_vertical = fit_orbit[2]
    elif labels == 'yz':
        pot_args = [0 | units.parsec, X, Y]
        fit_horizontal = fit_orbit[1]
        fit_vertical = fit_orbit[2]

    phi = potential.get_potential_at_point(None, *pot_args)
    aplot.imshow_color_plot(X, Y, phi, cmap="Blues")
    del aplot.UnitlessArgs.arg_units[2]

    aplot.scatter(0 | units.parsec, 0 | units.parsec, c='black')
    aplot.plot(fit_horizontal, fit_vertical, c="green", ls="--",
               label="Kruijssen et al. 2014")

    colors = cycle(['red', 'black', 'yellow', 'grey', 'green'])

    for full_orbit, code in zip(orbits, codes):
        horizontal = full_orbit.x if hor == 'x' else full_orbit.y
        vertical = full_orbit.y if vert == 'y' else full_orbit.z
        color = next(colors)
        aplot.plot(horizontal, vertical, c=color, label=code)
        aplot.scatter(horizontal[-1], vertical[-1], c=color, edgecolor=color)

    pyplot.axis('equal')
    aplot.xlim([-150, 150] | units.parsec)
    aplot.ylim([-150, 150] | units.parsec)
    aplot.xlabel(hor)
    aplot.ylabel(vert)
Example #55
0
def make_effective_iso_potential_plot(gravity_code):
    omega = (constants.G * gravity_code.particles.total_mass() /
             (1.0 | units.AU**3)).sqrt()
    center_of_mass = gravity_code.particles.center_of_mass()[:2]
    figure = pyplot.figure(figsize=(9, 8))
    current_axes = pyplot.subplot(2, 2, 1)
    current_axes.set_aspect("equal", adjustable="box")
    effective_iso_potential_plot(gravity_code,
                                 omega,
                                 center_of_rotation=center_of_mass,
                                 fraction_screen_filled=0.7)
    xlabel('x')
    ylabel('y')

    current_axes = pyplot.subplot(2, 2, 3)
    current_axes.set_aspect("equal", adjustable="box")
    effective_iso_potential_plot(gravity_code,
                                 omega,
                                 center_of_rotation=center_of_mass,
                                 xlim=[0.9, 1.1] | units.AU,
                                 ylim=[-0.1, 0.1] | units.AU,
                                 number_of_contours=20)
    xlabel('x')
    ylabel('y')

    gravity_code.particles[1].mass *= 10000
    omega = (constants.G * gravity_code.particles.total_mass() /
             (1.0 | units.AU**3)).sqrt()
    center_of_mass = gravity_code.particles.center_of_mass()[:2]
    current_axes = pyplot.subplot(2, 2, 2)
    current_axes.set_aspect("equal", adjustable="box")
    effective_iso_potential_plot(gravity_code,
                                 omega,
                                 center_of_rotation=center_of_mass,
                                 number_of_contours=20,
                                 fraction_screen_filled=0.7)
    xlabel('x')
    ylabel('y')

    current_axes = pyplot.subplot(2, 2, 4)
    current_axes.set_aspect("equal", adjustable="box")
    effective_iso_potential_plot(gravity_code,
                                 omega,
                                 center_of_rotation=center_of_mass,
                                 xlim=[0.6, 1.4] | units.AU,
                                 ylim=[-0.4, 0.4] | units.AU,
                                 number_of_contours=20,
                                 fraction_screen_filled=0.9)
    xlabel('x')
    ylabel('y')
    pyplot.show()
Example #56
0
def temperature_density_plot(data, mass, age):
    figure = pyplot.figure(figsize = (8, 10))
    pyplot.subplot(2, 1, 1)
    ax = pyplot.gca()
    plotT = semilogy(data["radius"], data["temperature"], 'r-', label = r'$T(r)$')
    xlabel('Radius')
    ylabel('Temperature')
    ax.twinx()
    plotrho = semilogy(data["radius"], data["density"], 'g-', label = r'$\rho(r)$')
    plots = plotT + plotrho
    labels = [one_plot.get_label() for one_plot in plots]
    ax.legend(plots, labels, loc=3)
    ylabel('Density')
    pyplot.subplot(2, 1, 2)
    semilogy(data["radius"], data["composition"][0], label = data["species_names"][0])
    semilogy(data["radius"], data["composition"][1], label = data["species_names"][1])
    semilogy(data["radius"], data["composition"][2], label = data["species_names"][2])
    semilogy(data["radius"], data["composition"][3], label = data["species_names"][3])
    semilogy(data["radius"], data["composition"][4], label = data["species_names"][4])
    pyplot.ylim(0.0, 1.0)
    xlabel('Radius')
    ylabel('Mass fraction')
    pyplot.legend()
    pyplot.suptitle('Structure of a {0} star at {1}'.format(mass, age))
    pyplot.show()   
Example #57
0
        native_plot, plot, scatter, xlabel, ylabel, hist
        )
import numpy as np

if __name__ == "__main__":

    # latex_support()

    x = np.pi/20.0 * (range(-10, 10) | units.m)
    y1 = units.MSun.new_quantity(np.sin(x.number))
    y2 = units.MSun.new_quantity(x.number)
    native_plot.subplot(2, 2, 1)
    plot(x, y2, label='model')
    scatter(x, y1, label='data')
    xlabel('x')
    ylabel('mass [$M_\odot$]')  # overrides auto unit!
    native_plot.legend(loc=2)

    x = range(50) | units.Myr
    y1 = quantities.new_quantity(
        np.sin(np.arange(0, 1.5, 0.03)), 1e50*units.erg)
    y2 = -(1e43 | units.J) - y1
    native_plot.subplot(2, 2, 2)
    plot(x, y1, label='$E_\mathrm{kin}$')
    plot(x, y2, label='$E_\mathrm{pot}$')
    xlabel('t')
    ylabel('E')
    native_plot.legend()

    x = range(7) | units.day
    y1 = [0, 4, 2, 3, 2, 5, 1]