Exemple #1
0
def plot_degen_vs_time(df, filename=None, show=False, limits=None,
        scale=['linear','linear']):

    # Import external modules
    import numpy as np
    import math
    import pyfits as pf
    import matplotlib.pyplot as plt
    import matplotlib
    from mpl_toolkits.axes_grid1 import ImageGrid
    from astroML.plotting import scatter_contour
    from itertools import cycle
    from matplotlib.ticker import FormatStrFormatter
    from matplotlib.ticker import ScalarFormatter
    import myplotting as myplt

    # Set up plot aesthetics
    # ----------------------
    plt.close;plt.clf()
    plt.rcdefaults()

    # Color map
    cmap = plt.cm.gnuplot

    # Color cycle, grabs colors from cmap
    color_cycle = [cmap(i) for i in np.linspace(0, 0.8, 5)]
    font_scale = 13
    line_weight = 600
    font_weight = 600

    params = {
              'axes.color_cycle': color_cycle, # colors of different plots
              'axes.labelsize': font_scale,
              'axes.titlesize': font_scale,
              #'axes.weight': line_weight,
              'axes.linewidth': 1.2,
              'axes.labelweight': font_weight,
              'legend.fontsize': font_scale*3/4,
              'xtick.labelsize': font_scale,
              'ytick.labelsize': font_scale,
              'font.weight': font_weight,
              'font.serif': 'computer modern roman',
              'text.fontsize': font_scale,
              'text.usetex': True,
              #'text.latex.preamble': r'\usepackage[T1]{fontenc}',
              #'font.family': 'sans-serif',
              'figure.figsize': (5, 5),
              'figure.dpi': 600,
              'backend' : 'pdf',
              #'figure.titlesize': font_scale,
             }
    plt.rcParams.update(params)

    # Create figure instance
    fig = plt.figure()

    ax = fig.add_subplot(111)

    lines = ["-","--","-.",":"]
    linecycler = cycle(lines)


    for i, Z in enumerate([0.0001, 0.001, 0.01, 0.03]):
        Z = str(Z)
        ax.plot(df[Z]['Time [years]'] / 10**10,
                df[Z]['Degeneracy'],
                #linestyle=next(linecycler),
                label=r'Z = {0:s}'.format(Z)
                )

    if limits is not None:
        ax.set_xlim(limits[0],limits[1])
        ax.set_ylim(limits[2],limits[3])


    # set scales, linear or log
    ax.set_xscale(scale[0])
    ax.set_yscale(scale[1])

    # change labels to be integer scalars
    if 0:
        fig.canvas.draw()
        ax.xaxis.set_major_formatter(ScalarFormatter())
        ax.xaxis.set_minor_formatter(ScalarFormatter())
    if 1:
        ax.xaxis.set_major_formatter(ScalarFormatter())
        ax.xaxis.set_minor_formatter(ScalarFormatter())

    #ax.xaxis.set_minor_formatter(FormatStrFormatter('%.1f'))

    # Make sure no tick labels are overplotting one another
    ax = myplt.delete_overlapping_xlabels(fig, ax)

    #ax.xaxis.set_minor_formatter(FormatStrFormatter('%.1f'))

    # Make sure no tick labels are overplotting one another
    #ax = myplt.delete_overlapping_xlabels(fig, ax)

    # Adjust asthetics
    ax.set_xlabel(r'Time [10 Gyr]')
    ax.set_ylabel(r'Central Electron Degeneracy Parameter')
    ax.legend(loc='best')

    #ax.locator_params(nbins=5, axis='x')

    if filename is not None:
        plt.tight_layout()
        plt.savefig(filename, bbox_inches='tight')
    if show:
        fig.show()
Exemple #2
0
def plot_L_vs_T(df,
                filename=None,
                show=False,
                limits=None,
                scale=['linear', 'linear']):

    # Import external modules
    import numpy as np
    import math
    import pyfits as pf
    import matplotlib.pyplot as plt
    import matplotlib
    from mpl_toolkits.axes_grid1 import ImageGrid
    from astroML.plotting import scatter_contour
    from itertools import cycle
    from matplotlib.ticker import FormatStrFormatter
    from matplotlib.ticker import ScalarFormatter
    import myplotting as myplt

    # Set up plot aesthetics
    # ----------------------
    plt.close
    plt.clf()
    plt.rcdefaults()

    # Color map
    cmap = plt.cm.gnuplot

    # Color cycle, grabs colors from cmap
    color_cycle = [cmap(i) for i in np.linspace(0, 0.8, 5)]
    font_scale = 13
    line_weight = 600
    font_weight = 600

    params = {
        'axes.color_cycle': color_cycle,  # colors of different plots
        'axes.labelsize': font_scale,
        'axes.titlesize': font_scale,
        #'axes.weight': line_weight,
        'axes.linewidth': 1.2,
        'axes.labelweight': font_weight,
        'legend.fontsize': font_scale * 3 / 4,
        'xtick.labelsize': font_scale,
        'ytick.labelsize': font_scale,
        'font.weight': font_weight,
        'font.serif': 'computer modern roman',
        'text.fontsize': font_scale,
        'text.usetex': True,
        #'text.latex.preamble': r'\usepackage[T1]{fontenc}',
        #'font.family': 'sans-serif',
        'figure.figsize': (5, 5),
        'figure.dpi': 600,
        'backend': 'pdf',
        #'figure.titlesize': font_scale,
    }
    plt.rcParams.update(params)

    # Create figure instance
    fig = plt.figure()

    ax = fig.add_subplot(111)

    lines = ["-", "--", "-.", ":"]
    linecycler = cycle(lines)

    #for i, Z in enumerate(df):
    for i, Z in enumerate([0.0001, 0.001, 0.01, 0.03]):
        Z = str(Z)
        ax.plot(
            df[Z]['Teff [K]'],
            df[Z]['Luminosity [Lsun]'],
            #linestyle=next(linecycler),
            label=r'Z = {0:s}'.format(Z))

    if limits is not None:
        ax.set_xlim(limits[0], limits[1])
        ax.set_ylim(limits[2], limits[3])

    # set scales, linear or log
    ax.set_xscale(scale[0])
    ax.set_yscale(scale[1])

    # change labels to be integer scalars
    fig.canvas.draw()
    if 1:
        ax.xaxis.set_major_formatter(ScalarFormatter())
        ax.xaxis.set_minor_formatter(ScalarFormatter())

    #ax.xaxis.set_minor_formatter(FormatStrFormatter('%.1f'))

    # Make sure no tick labels are overplotting one another
    ax = myplt.delete_overlapping_xlabels(fig, ax)

    # Adjust asthetics
    ax.set_xlabel(r'$T_{\rm eff}$ [K]')
    ax.set_ylabel(r'L [L$_\odot$]')
    ax.legend(loc='best')

    #ax.locator_params(nbins=5, axis='x')

    if filename is not None:
        plt.tight_layout()
        plt.savefig(filename, bbox_inches='tight')
    if show:
        fig.show()