def plot_modelparam_cdfs(core_dict, df):

    import myplotting as myplt
    import matplotlib.pyplot as plt
    import mystats
    # Import external modules
    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1 import AxesGrid
    import pywcsgrid2 as wcs
    from matplotlib.patches import Polygon
    import matplotlib.patheffects as PathEffects
    import myplotting as myplt

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

    # Color map
    cmap = plt.cm.copper

    # Color cycle, grabs colors from cmap
    c_cycle = [cmap(i) for i in np.linspace(0, 0.8, 3)]
    font_scale = 9

    # Create figure instance
    fig = plt.figure(figsize=(3.5, 5))

    parameters = [
        'phi_cnm',
        'alphaG',
    ]

    fig, axes = plt.subplots(2, 1, sharey=True, figsize=(3.5, 5))

    clouds = 'california', 'perseus', 'taurus'
    linestyles = ['-', '--', '-.']

    include_errors = True
    for i, cloud in enumerate(clouds):
        phi_cnms = []
        phi_cnms_error = []
        alphaGs = []
        alphaGs_error = []
        for core in core_dict:
            if core_dict[core]['cloud'] == cloud:
                phi_cnms.append(core_dict[core]['krumholz']['phi_cnm'])
                alphaGs.append(core_dict[core]['sternberg']['alphaG'])
                phi_cnms_error.append(
                    core_dict[core]['krumholz']['phi_cnm_error'])
                alphaGs_error.append(
                    core_dict[core]['sternberg']['alphaG_error'])

        alphaGs = np.array(alphaGs)
        alphaGs_error = np.array(alphaGs_error)
        phi_cnms = np.array(phi_cnms)
        phi_cnms_error = np.array(phi_cnms_error)

        if include_errors:
            n_sim = 100000
            alpha = 1.0 / n_sim
            alpha = 0.1
            if 0:
                for j in xrange(n_sim):
                    phi_cnm_sim = \
                        phi_cnms + np.random.normal(scale=phi_cnms_error[:, 0])
                    alphaG_sim = \
                            alphaGs + np.random.normal(scale=alphaGs_error[:, 0])
                    if j == 0:
                        label = cloud.capitalize()
                        x = axes[0].plot(
                            0,
                            0,
                            label=label,
                            color=c_cycle[i],
                        )
                    else:
                        label = None
                    x = myplt.plot_cdf(phi_cnm_sim,
                                       ax=axes[0],
                                       plot_kwargs={#'label': label,
                                                    'color': c_cycle[i],
                                                    #'linestyle': linestyles[i],
                                                    'alpha': alpha,
                                                    })

                    x = myplt.plot_cdf(alphaG_sim,
                                       ax=axes[1],
                                       plot_kwargs={#'label': label,
                                                    'color': c_cycle[i],
                                                    #'linestyle': linestyles[i],
                                                    'alpha': alpha,
                                                    })
            else:
                label = cloud.capitalize()
                linestyle = linestyles[i]
                nbins = 20
                alpha = 0.3
                axes[0].plot(
                    0,
                    0,
                    label=label,
                    color=c_cycle[i],
                )
                myplt.plot_cdf_confint(phi_cnms,
                                       data_error=phi_cnms_error[:,0],
                                       ax=axes[0],
                                       nsim=n_sim,
                                       nbins=nbins,
                                       #bin_limits=[0, None],
                                       plot_kwargs_line={'color': c_cycle[i],
                                                         'linestyle': linestyle,
                                                         'linestyle': linestyles[i],
                                                         },
                                       plot_kwargs_fill_between=\
                                               {'color': c_cycle[i],
                                                'alpha': alpha,
                                                'linewidth': 0,
                                                },
                                       )
                myplt.plot_cdf_confint(alphaGs,
                                       data_error=alphaGs_error[:,0],
                                       ax=axes[1],
                                       nsim=n_sim,
                                       nbins=nbins,
                                       plot_kwargs_line={'color': c_cycle[i],
                                                         'linestyle': linestyle,
                                                         },
                                       plot_kwargs_fill_between=\
                                             {'color': c_cycle[i],
                                              'alpha': alpha,
                                              'linewidth': 0,
                                              },
                                       )
        else:
            x = myplt.plot_cdf(phi_cnms,
                               ax=axes[0],
                               plot_kwargs={
                                   'label': cloud.capitalize(),
                                   'color': c_cycle[i],
                                   'linestyle': linestyles[i],
                               })

            x = myplt.plot_cdf(alphaGs,
                               ax=axes[1],
                               plot_kwargs={
                                   'label': cloud.capitalize(),
                                   'color': c_cycle[i],
                                   'linestyle': linestyles[i],
                               })

    axes[0].legend(loc='lower right')
    #ax.set_xscale('log')
    axes[0].set_xlabel(r'$\phi_{\rm CNM}$')
    axes[1].set_xlabel(r'$\alpha G$')
    axes[0].set_ylabel('Cumulative Distribution')
    axes[1].set_ylabel('Cumulative Distribution')
    axes[0].set_ylim([0, 1])
    axes[1].set_ylim([0, 1])
    axes[0].set_xlim([0, 25])
    axes[1].set_xlim([0, 60])

    #plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/temps_cdf.png')
    plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/modelparams_cdf.pdf')
def plot_modelparam_cdfs(core_dict, df):

    import myplotting as myplt
    import matplotlib.pyplot as plt
    import mystats
    # Import external modules
    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1 import AxesGrid
    import pywcsgrid2 as wcs
    from matplotlib.patches import Polygon
    import matplotlib.patheffects as PathEffects
    import myplotting as myplt

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

    # Color map
    cmap = plt.cm.copper

    # Color cycle, grabs colors from cmap
    c_cycle = [cmap(i) for i in np.linspace(0, 0.8, 3)]
    font_scale = 9

    # Create figure instance
    fig = plt.figure(figsize=(3.5, 5))

    parameters = ['phi_cnm', 'alphaG',]

    fig, axes = plt.subplots(2,1,sharey=True, figsize=(3.5, 5))

    clouds = 'california', 'perseus', 'taurus'
    linestyles = ['-', '--', '-.']

    include_errors = True
    for i, cloud in enumerate(clouds):
        phi_cnms = []
        phi_cnms_error = []
        alphaGs = []
        alphaGs_error = []
        for core in core_dict:
            if core_dict[core]['cloud'] == cloud:
                phi_cnms.append(core_dict[core]['krumholz']['phi_cnm'])
                alphaGs.append(core_dict[core]['sternberg']['alphaG'])
                phi_cnms_error.append(core_dict[core]['krumholz']['phi_cnm_error'])
                alphaGs_error.append(core_dict[core]['sternberg']['alphaG_error'])

        alphaGs = np.array(alphaGs)
        alphaGs_error = np.array(alphaGs_error)
        phi_cnms = np.array(phi_cnms)
        phi_cnms_error = np.array(phi_cnms_error)

        if include_errors:
            n_sim = 100000
            alpha = 1.0 / n_sim
            alpha = 0.1
            if 0:
                for j in xrange(n_sim):
                    phi_cnm_sim = \
                        phi_cnms + np.random.normal(scale=phi_cnms_error[:, 0])
                    alphaG_sim = \
                            alphaGs + np.random.normal(scale=alphaGs_error[:, 0])
                    if j == 0:
                        label = cloud.capitalize()
                        x = axes[0].plot(0,0,
                                         label=label,
                                         color=c_cycle[i],
                                         )
                    else:
                        label = None
                    x = myplt.plot_cdf(phi_cnm_sim,
                                       ax=axes[0],
                                       plot_kwargs={#'label': label,
                                                    'color': c_cycle[i],
                                                    #'linestyle': linestyles[i],
                                                    'alpha': alpha,
                                                    })

                    x = myplt.plot_cdf(alphaG_sim,
                                       ax=axes[1],
                                       plot_kwargs={#'label': label,
                                                    'color': c_cycle[i],
                                                    #'linestyle': linestyles[i],
                                                    'alpha': alpha,
                                                    })
            else:
                label = cloud.capitalize()
                linestyle = linestyles[i]
                nbins = 20
                alpha = 0.3
                axes[0].plot(0,0,
                             label=label,
                             color=c_cycle[i],
                             )
                myplt.plot_cdf_confint(phi_cnms,
                                       data_error=phi_cnms_error[:,0],
                                       ax=axes[0],
                                       nsim=n_sim,
                                       nbins=nbins,
                                       #bin_limits=[0, None],
                                       plot_kwargs_line={'color': c_cycle[i],
                                                         'linestyle': linestyle,
                                                         'linestyle': linestyles[i],
                                                         },
                                       plot_kwargs_fill_between=\
                                               {'color': c_cycle[i],
                                                'alpha': alpha,
                                                'linewidth': 0,
                                                },
                                       )
                myplt.plot_cdf_confint(alphaGs,
                                       data_error=alphaGs_error[:,0],
                                       ax=axes[1],
                                       nsim=n_sim,
                                       nbins=nbins,
                                       plot_kwargs_line={'color': c_cycle[i],
                                                         'linestyle': linestyle,
                                                         },
                                       plot_kwargs_fill_between=\
                                             {'color': c_cycle[i],
                                              'alpha': alpha,
                                              'linewidth': 0,
                                              },
                                       )
        else:
            x = myplt.plot_cdf(phi_cnms,
                               ax=axes[0],
                               plot_kwargs={'label': cloud.capitalize(),
                                            'color': c_cycle[i],
                                            'linestyle': linestyles[i],
                                            })

            x = myplt.plot_cdf(alphaGs,
                               ax=axes[1],
                               plot_kwargs={'label': cloud.capitalize(),
                                            'color': c_cycle[i],
                                            'linestyle': linestyles[i],
                                            })

    axes[0].legend(loc='lower right')
    #ax.set_xscale('log')
    axes[0].set_xlabel(r'$\phi_{\rm CNM}$')
    axes[1].set_xlabel(r'$\alpha G$')
    axes[0].set_ylabel('Cumulative Distribution')
    axes[1].set_ylabel('Cumulative Distribution')
    axes[0].set_ylim([0,1])
    axes[1].set_ylim([0,1])
    axes[0].set_xlim([0,25])
    axes[1].set_xlim([0,60])

    #plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/temps_cdf.png')
    plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/modelparams_cdf.pdf')
def plot_density_cdfs(core_dict, df):

    import myplotting as myplt
    import matplotlib.pyplot as plt
    import mystats
    import myscience

    # load Stanimirovic temps
    filename = \
            '/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
            'stanimirovic14_temps.npy'
    stani_temps = np.loadtxt(filename)
    filename = \
            '/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
            'stanimirovic14_temp_errors.npy'
    stani_temp_errors = np.loadtxt(filename)
    stani_temp_errors = np.array((stani_temp_errors, stani_temp_errors)).T
    filename = \
            '/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
            'stanimirovic14_int_temps.npy'
    stani_tempKs = np.loadtxt(filename)

    # load the dict
    with open('/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
              'stanimirovic14_temps.pickle', 'rb') as f:
        temp_dict = pickle.load(f)

    # concatenate the temps from each cloud
    Ts_list = []
    Ts_error_list = []
    Ts_avg_list = []
    Ts_avg_error_list = []
    for cloud in temp_dict:
        for Ts in temp_dict[cloud]['Ts_list']:
            Ts_list.append(Ts)
        for Ts_error in temp_dict[cloud]['Ts_error_list']:
            Ts_error_list.append(Ts_error)
        for Ts_avg in temp_dict[cloud]['Ts_avg_list']:
            #for Ts_avg in temp_dict[cloud]['Tk_list']:
            Ts_avg_list.append(Ts_avg)
        for Ts_avg_error in temp_dict[cloud]['Ts_avg_error_list']:
            #for Ts_avg_error in temp_dict[cloud]['Tk_error_list']:
            Ts_avg_error_list.append(Ts_avg_error)

    Ts_list = np.array(Ts_list)
    Ts_error_list = np.array(Ts_error_list)
    Ts_avg_list = np.array(Ts_avg_list)
    Ts_avg_error_list = np.array(Ts_avg_error_list)

    print '\nNumber of LOS:', len(Ts_avg_list)

    # collect data
    T_cnms = np.empty(len(core_dict))
    T_Hs = np.empty(len(core_dict))
    T_cnm_errors = np.empty((len(core_dict), 2))
    T_H_errors = np.empty((len(core_dict), 2))
    n_cnms = np.empty(len(core_dict))
    n_Hs = np.empty(len(core_dict))
    n_cnm_errors = np.empty((len(core_dict), 2))
    n_H_errors = np.empty((len(core_dict), 2))

    for i, core_name in enumerate(core_dict):
        core = core_dict[core_name]
        T_cnms[i] = core['T_cnm']
        T_Hs[i] = core['T_H'] * 1000.0
        T_cnm_errors[i] = core['T_cnm_error']
        T_H_errors[i] = core['T_H_error'] * 1000.0
        n_cnms[i] = core['n_cnm']
        n_Hs[i] = core['n_H']
        n_cnm_errors[i] = core['n_cnm_error']
        n_H_errors[i] = core['n_H_error']

    # Make plot
    #plt.close;plt.clf()

    # Create figure instance
    fig = plt.figure(figsize=(3.5, 2.5))
    ax = fig.add_subplot(111)
    c_cycle = myplt.set_color_cycle(4, cmap_limits=(0.0, 0.9))

    #data_list = [stani_temps, stani_tempKs, T_cnms, T_Hs]
    data_list = [Ts_list, Ts_avg_list, T_cnms, T_Hs]
    data_error_list = [
        stani_temp_errors,
        np.array(((5), )), T_cnm_errors, T_H_errors
    ]
    if 1:
        data_names = [
            r'Stanimirovic+14 $n_{\rm s}$', r'Stanimirovic+14 $<n_s>$',
            r'$n_{\rm CNM}$', r'$n_H$'
        ]
    else:
        data_names = [
            r'Stanimirovi$\acute{c}$+14' + '\n' + r'$T_{\rm s}$',
            r'Stanimirovi$\acute{c}$+14' + '\n' + r'$<T_{\rm s}>$',
            r'$T_{\rm CNM}$', r'$T_H$'
        ]

    linestyles = ['--', '-.', ':', '-']

    # Plot MC sim of error?
    include_errors = True

    # Define pressures
    P = 3700.
    P_error = [1200., 1200.]
    P_low = P - P_error[0]
    P_hi = P + P_error[1]

    for i, data in enumerate(data_list):
        data = np.array(data)
        if i < 2:
            include_errors = True
        else:
            include_errors = True

        if include_errors:
            if i == 0:
                #n = P / data
                T = Ts_list
                T_error = Ts_error_list
                n, n_error = myscience.calc_density(
                    T_H=T,
                    pressure=P,
                    pressure_error=P_error[0],
                    T_H_error=T_error,
                    calc_error=True,
                )
            elif i == 1:
                #n = P / data
                T = Ts_avg_list
                T_error = Ts_avg_error_list
                n, n_error = myscience.calc_density(
                    T_H=T,
                    pressure=P,
                    pressure_error=P_error[0],
                    T_H_error=T_error,
                    calc_error=True,
                )
            elif i == 2:
                n = n_cnms
                n_error = n_cnm_errors[:, 0]
                T = T_cnms
                T_error = T_cnm_errors[:, 0]
            elif i == 3:
                n = n_Hs
                n_error = n_H_errors[:, 0]
                T = T_Hs
                T_error = T_H_errors[:, 0]
            if 0:
                n_sim = 100
                alpha = 1.0 / n_sim
                alpha = 0.1
                for j in xrange(n_sim):
                    if 0:
                        error = data_error_list[i]
                        data_sim = data + np.random.normal(scale=error[:, 0])
                    else:
                        pressure = P + np.random.normal(scale=(P - P_low),
                                                        size=data.size)
                        data_sim = pressure / (n + np.random.normal(n_error))

                    x = myplt.plot_cdf(
                        data_sim,
                        ax=ax,
                        plot_kwargs={  #'label': label,
                            'color': c_cycle[i],
                            'alpha': alpha
                        })
            else:
                linestyle = linestyles[i]
                label = data_names[i]
                alpha = 0.3
                nbins = 20
                error = n_error
                data = n
                n_sim = 100000
                mask = (error > data)
                data = data[~mask]
                error = error[~mask]
                if 1:
                    myplt.plot_cdf_confint(data,
                                           data_error=error,
                                           ax=ax,
                                           nsim=n_sim,
                                           nbins=nbins,
                                           bin_limits=[-20, 300],
                                           plot_kwargs_line={'color': c_cycle[i],
                                                             'linestyle': linestyle,
                                                             'label': label,
                                                             'linewidth' : 1.5,
                                                             },
                                           plot_kwargs_fill_between=\
                                                   {'color': c_cycle[i],
                                                    'alpha': alpha,
                                                    'linewidth': 0,
                                                    },
                                           )
        #if i < 2:
        if 0:
            x = myplt.plot_cdf(data[data > 0],
                               ax=ax,
                               plot_kwargs={
                                   'label': data_names[i],
                                   'color': c_cycle[i],
                                   'linestyle': linestyles[i],
                                   'linewidth': 2,
                                   'zorder': 1000
                               })
        else:
            if 0:
                x = myplt.plot(
                    (0, 0),
                    ax=ax,
                    plot_kwargs={
                        'label': data_names[i],
                        'color': c_cycle[i],
                        'linestyle': linestyles[i]
                    })

    ax.legend(loc='best')
    if 1:
        ax.set_xscale('linear')
        ax.set_xlim([-10, 200])
    else:
        ax.set_xscale('log')
        ax.set_xlim([7 * 10**-1, 10**4])
    ax.set_ylim([0, 1])

    ax.set_xlabel(r'Neutral Gas Density [cm$^{-3}$]')
    ax.set_ylabel('Cumulative Distribution')

    #plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/temps_cdf.png')
    plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/density_cdf.pdf')
def plot_density_cdfs(core_dict, df):

    import myplotting as myplt
    import matplotlib.pyplot as plt
    import mystats
    import myscience

    # load Stanimirovic temps
    filename = \
            '/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
            'stanimirovic14_temps.npy'
    stani_temps = np.loadtxt(filename)
    filename = \
            '/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
            'stanimirovic14_temp_errors.npy'
    stani_temp_errors = np.loadtxt(filename)
    stani_temp_errors = np.array((stani_temp_errors, stani_temp_errors)).T
    filename = \
            '/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
            'stanimirovic14_int_temps.npy'
    stani_tempKs = np.loadtxt(filename)

    # load the dict
    with open('/d/bip3/ezbc/multicloud/data/python_output/tables/' + \
              'stanimirovic14_temps.pickle', 'rb') as f:
        temp_dict = pickle.load(f)

    # concatenate the temps from each cloud
    Ts_list = []
    Ts_error_list = []
    Ts_avg_list = []
    Ts_avg_error_list = []
    for cloud in temp_dict:
        for Ts in temp_dict[cloud]['Ts_list']:
            Ts_list.append(Ts)
        for Ts_error in temp_dict[cloud]['Ts_error_list']:
            Ts_error_list.append(Ts_error)
        for Ts_avg in temp_dict[cloud]['Ts_avg_list']:
        #for Ts_avg in temp_dict[cloud]['Tk_list']:
            Ts_avg_list.append(Ts_avg)
        for Ts_avg_error in temp_dict[cloud]['Ts_avg_error_list']:
        #for Ts_avg_error in temp_dict[cloud]['Tk_error_list']:
            Ts_avg_error_list.append(Ts_avg_error)

    Ts_list = np.array(Ts_list)
    Ts_error_list = np.array(Ts_error_list)
    Ts_avg_list = np.array(Ts_avg_list)
    Ts_avg_error_list = np.array(Ts_avg_error_list)

    print '\nNumber of LOS:', len(Ts_avg_list)

    # collect data
    T_cnms = np.empty(len(core_dict))
    T_Hs = np.empty(len(core_dict))
    T_cnm_errors = np.empty((len(core_dict), 2))
    T_H_errors = np.empty((len(core_dict), 2))
    n_cnms = np.empty(len(core_dict))
    n_Hs = np.empty(len(core_dict))
    n_cnm_errors = np.empty((len(core_dict), 2))
    n_H_errors = np.empty((len(core_dict), 2))

    for i, core_name in enumerate(core_dict):
        core = core_dict[core_name]
        T_cnms[i] = core['T_cnm']
        T_Hs[i] = core['T_H'] * 1000.0
        T_cnm_errors[i] = core['T_cnm_error']
        T_H_errors[i] = core['T_H_error'] * 1000.0
        n_cnms[i] = core['n_cnm']
        n_Hs[i] = core['n_H']
        n_cnm_errors[i] = core['n_cnm_error']
        n_H_errors[i] = core['n_H_error']

    # Make plot
    #plt.close;plt.clf()

    # Create figure instance
    fig = plt.figure(figsize=(3.5, 2.5))
    ax = fig.add_subplot(111)
    c_cycle = myplt.set_color_cycle(4, cmap_limits=(0.0, 0.9))

    #data_list = [stani_temps, stani_tempKs, T_cnms, T_Hs]
    data_list = [Ts_list, Ts_avg_list, T_cnms, T_Hs]
    data_error_list = [stani_temp_errors, np.array(((5),)),
                       T_cnm_errors, T_H_errors]
    if 1:
        data_names = [r'Stanimirovic+14 $n_{\rm s}$',
                      r'Stanimirovic+14 $<n_s>$',
                      r'$n_{\rm CNM}$',
                      r'$n_H$']
    else:
        data_names = [r'Stanimirovi$\acute{c}$+14' + '\n' + r'$T_{\rm s}$',
                      r'Stanimirovi$\acute{c}$+14' + '\n' + r'$<T_{\rm s}>$',
                      r'$T_{\rm CNM}$',
                      r'$T_H$']

    linestyles = ['--', '-.', ':', '-']

    # Plot MC sim of error?
    include_errors = True

    # Define pressures
    P = 3700.
    P_error = [1200., 1200.]
    P_low = P - P_error[0]
    P_hi = P + P_error[1]

    for i, data in enumerate(data_list):
        data = np.array(data)
        if i < 2:
            include_errors = True
        else:
            include_errors = True

        if include_errors:
            if i == 0:
                #n = P / data
                T = Ts_list
                T_error = Ts_error_list
                n, n_error = myscience.calc_density(T_H=T,
                                                    pressure=P,
                                                    pressure_error=P_error[0],
                                                    T_H_error=T_error,
                                                    calc_error=True,
                                                    )
            elif i == 1:
                #n = P / data
                T = Ts_avg_list
                T_error = Ts_avg_error_list
                n, n_error = myscience.calc_density(T_H=T,
                                                    pressure=P,
                                                    pressure_error=P_error[0],
                                                    T_H_error=T_error,
                                                    calc_error=True,
                                                    )
            elif i == 2:
                n = n_cnms
                n_error = n_cnm_errors[:, 0]
                T = T_cnms
                T_error = T_cnm_errors[:, 0]
            elif i == 3:
                n = n_Hs
                n_error = n_H_errors[:, 0]
                T = T_Hs
                T_error = T_H_errors[:, 0]
            if 0:
                n_sim = 100
                alpha = 1.0 / n_sim
                alpha = 0.1
                for j in xrange(n_sim):
                    if 0:
                        error = data_error_list[i]
                        data_sim = data + np.random.normal(scale=error[:, 0])
                    else:
                        pressure = P + np.random.normal(scale=(P - P_low),
                                                        size=data.size)
                        data_sim = pressure / (n + np.random.normal(n_error))

                    x = myplt.plot_cdf(data_sim,
                                       ax=ax,
                                       plot_kwargs={#'label': label,
                                                    'color': c_cycle[i],
                                                    'alpha': alpha})
            else:
                linestyle = linestyles[i]
                label = data_names[i]
                alpha = 0.3
                nbins = 20
                error = n_error
                data = n
                n_sim = 100000
                mask = (error > data)
                data = data[~mask]
                error = error[~mask]
                if 1:
                    myplt.plot_cdf_confint(data,
                                           data_error=error,
                                           ax=ax,
                                           nsim=n_sim,
                                           nbins=nbins,
                                           bin_limits=[-20, 300],
                                           plot_kwargs_line={'color': c_cycle[i],
                                                             'linestyle': linestyle,
                                                             'label': label,
                                                             'linewidth' : 1.5,
                                                             },
                                           plot_kwargs_fill_between=\
                                                   {'color': c_cycle[i],
                                                    'alpha': alpha,
                                                    'linewidth': 0,
                                                    },
                                           )
        #if i < 2:
        if 0:
            x = myplt.plot_cdf(data[data > 0],
                               ax=ax,
                               plot_kwargs={'label': data_names[i],
                                            'color': c_cycle[i],
                                            'linestyle': linestyles[i],
                                            'linewidth': 2,
                                            'zorder': 1000})
        else:
            if 0:
                x = myplt.plot((0,0),
                                ax=ax,
                                plot_kwargs={'label': data_names[i],
                                             'color': c_cycle[i],
                                             'linestyle': linestyles[i]})

    ax.legend(loc='best')
    if 1:
        ax.set_xscale('linear')
        ax.set_xlim([-10, 200])
    else:
        ax.set_xscale('log')
        ax.set_xlim([7*10**-1, 10**4])
    ax.set_ylim([0,1])

    ax.set_xlabel(r'Neutral Gas Density [cm$^{-3}$]')
    ax.set_ylabel('Cumulative Distribution')

    #plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/temps_cdf.png')
    plt.savefig('/d/bip3/ezbc/multicloud/figures/temps/density_cdf.pdf')