# Path: frbpoppy/misc.py
# def hist(parameter, bin_type='lin', n_bins=25, norm='max', edges=True,
#          bins=None):
#     """Bin up a parameter either in a lin or log space.
# 
#     Why is this not a standard option in numpy or matplotlib?
# 
#     Args:
#         parameter (array): To be binned
#         bin_type (str): Either 'lin', 'log' or 'ln'
#         n_bins (int): Number of bins. Can be overriden internally
#         norm (bool): Whether to normalise to 'max' or 'prob' or none
# 
#     Returns:
#         tuple: bin centers, values per bin
# 
#     """
#     if isinstance(parameter, list):
#         parameter = np.array(parameter)
# 
#     if len(parameter) == 0:
#         return np.nan, np.nan
# 
#     # Drop NaN-values
#     parameter = parameter[~(np.isnan(parameter) | np.isinf(parameter))]
# 
#     # Determine number of bins
#     if n_bins != 25:
#         pass
#     elif len(parameter) < 50:
#         n_bins = 15
#     elif len(parameter) > 500:
#         n_bins = 50
# 
#     # Determine type of binning
#     if bin_type == 'lin':
#         _bins = n_bins
#     elif bin_type == 'log':
#         min_f = np.log10(np.min(parameter[parameter != 0]))
#         max_f = np.log10(max(parameter))
#         _bins = np.logspace(min_f, max_f, n_bins)
#     elif bin_type == 'ln':
#         min_f = np.log(np.min(parameter[parameter != 0]))
#         max_f = np.log(max(parameter))
#         _bins = np.logspace(min_f, max_f, n_bins, base=np.e)
# 
#     # Allow for custom bins
#     if bins is not None:
#         _bins = bins
# 
#     # Allow for probability weighting
#     weights = None
#     if norm == 'prob':
#         weights = np.ones(len(parameter)) / len(parameter)
# 
#     # Bin
#     n, bin_edges = np.histogram(parameter, bins=_bins, weights=weights)
# 
#     if norm == 'max':
#         n = n/max(n)  # Normalise
# 
#     # Centre bins
#     bins = (bin_edges[:-1] + bin_edges[1:]) / 2
# 
#     # Ensure there are edges on the outer bins of the histograms
#     if edges:
#         if bin_type == 'lin':
#             bin_dif = np.diff(bins)[-1]
#             bins = np.insert(bins, 0, bins[0] - bin_dif)
#             bins = np.insert(bins, len(bins), bins[-1] + bin_dif)
#             n = np.insert(n, 0, 0)
#             n = np.insert(n, len(n), 0)
#         else:
#             bin_dif = np.diff(np.log10(bins))[-1]
#             bins = np.insert(bins, 0, 10**(np.log10(bins[0])-bin_dif))
#             bins = np.insert(bins, len(bins), 10**(np.log10(bins[-1])+bin_dif))
#             n = np.insert(n, 0, 0)
#             n = np.insert(n, len(n), 0)
# 
#     return bins, n
# 
# Path: tests/convenience.py
# def plot_aa_style(cols=1):
#     """Use a plotting style specifically for Astronomy & Astrophyiscs."""
#     # Use a style file
#     dir = os.path.abspath(os.path.dirname(__file__))
#     style_file = os.path.join(dir, './aa.mplstyle')
#     plt.style.use(style_file)
# 
#     # Check whether interactive backend is present
#     if os.name == 'posix' and "DISPLAY" not in os.environ:
#         # On a cluster
#         plt.switch_backend('Agg')
#         # Use just the basic latex package allowing \text to be used
#         plt.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
# 
#     if cols == 2:
#         plt.rcParams["figure.figsize"] = (5.75373, 3.556)
# 
# def rel_path(path):
#     """Return the relative path name for this directory."""
#     return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)


from frbpoppy import hist
from goodness_of_fit import GoodnessOfFit
from matplotlib.lines import Line2D
from scipy.optimize import curve_fit
from tests.convenience import plot_aa_style, rel_path
import matplotlib.pyplot as plt
import numpy as np
        self.colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
        self.gf = GoodnessOfFit()
        self.df = self.gf.so.df

        # Calculate global maximums
        self.gm = {}
        for run in self.df.run.unique():
            self.gm[run] = self.gf.calc_global_max(run)
        print(self.gm)

        # Plot various subplots
        self.alpha()
        self.si()
        self.li()
        self.li_2()
        self.lum_min()
        self.lum_max()
        self.w_int_mean()
        self.w_int_std()
        self.legend()
        self.dm_igm_slope()
        self.dm_host()
        self.axes[3, 2].set_axis_off()

        # Plot run rectangles
        # self.runs()

        # Save plot
        plt.tight_layout()  # rect=[0, 0, 0.98, 1])
        plt.subplots_adjust(wspace=0.1)

# Path: frbpoppy/misc.py
# def hist(parameter, bin_type='lin', n_bins=25, norm='max', edges=True,
#          bins=None):
#     """Bin up a parameter either in a lin or log space.
# 
#     Why is this not a standard option in numpy or matplotlib?
# 
#     Args:
#         parameter (array): To be binned
#         bin_type (str): Either 'lin', 'log' or 'ln'
#         n_bins (int): Number of bins. Can be overriden internally
#         norm (bool): Whether to normalise to 'max' or 'prob' or none
# 
#     Returns:
#         tuple: bin centers, values per bin
# 
#     """
#     if isinstance(parameter, list):
#         parameter = np.array(parameter)
# 
#     if len(parameter) == 0:
#         return np.nan, np.nan
# 
#     # Drop NaN-values
#     parameter = parameter[~(np.isnan(parameter) | np.isinf(parameter))]
# 
#     # Determine number of bins
#     if n_bins != 25:
#         pass
#     elif len(parameter) < 50:
#         n_bins = 15
#     elif len(parameter) > 500:
#         n_bins = 50
# 
#     # Determine type of binning
#     if bin_type == 'lin':
#         _bins = n_bins
#     elif bin_type == 'log':
#         min_f = np.log10(np.min(parameter[parameter != 0]))
#         max_f = np.log10(max(parameter))
#         _bins = np.logspace(min_f, max_f, n_bins)
#     elif bin_type == 'ln':
#         min_f = np.log(np.min(parameter[parameter != 0]))
#         max_f = np.log(max(parameter))
#         _bins = np.logspace(min_f, max_f, n_bins, base=np.e)
# 
#     # Allow for custom bins
#     if bins is not None:
#         _bins = bins
# 
#     # Allow for probability weighting
#     weights = None
#     if norm == 'prob':
#         weights = np.ones(len(parameter)) / len(parameter)
# 
#     # Bin
#     n, bin_edges = np.histogram(parameter, bins=_bins, weights=weights)
# 
#     if norm == 'max':
#         n = n/max(n)  # Normalise
# 
#     # Centre bins
#     bins = (bin_edges[:-1] + bin_edges[1:]) / 2
# 
#     # Ensure there are edges on the outer bins of the histograms
#     if edges:
#         if bin_type == 'lin':
#             bin_dif = np.diff(bins)[-1]
#             bins = np.insert(bins, 0, bins[0] - bin_dif)
#             bins = np.insert(bins, len(bins), bins[-1] + bin_dif)
#             n = np.insert(n, 0, 0)
#             n = np.insert(n, len(n), 0)
#         else:
#             bin_dif = np.diff(np.log10(bins))[-1]
#             bins = np.insert(bins, 0, 10**(np.log10(bins[0])-bin_dif))
#             bins = np.insert(bins, len(bins), 10**(np.log10(bins[-1])+bin_dif))
#             n = np.insert(n, 0, 0)
#             n = np.insert(n, len(n), 0)
# 
#     return bins, n
# 
# Path: tests/convenience.py
# def plot_aa_style(cols=1):
#     """Use a plotting style specifically for Astronomy & Astrophyiscs."""
#     # Use a style file
#     dir = os.path.abspath(os.path.dirname(__file__))
#     style_file = os.path.join(dir, './aa.mplstyle')
#     plt.style.use(style_file)
# 
#     # Check whether interactive backend is present
#     if os.name == 'posix' and "DISPLAY" not in os.environ:
#         # On a cluster
#         plt.switch_backend('Agg')
#         # Use just the basic latex package allowing \text to be used
#         plt.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
# 
#     if cols == 2:
#         plt.rcParams["figure.figsize"] = (5.75373, 3.556)
# 
# def rel_path(path):
#     """Return the relative path name for this directory."""
#     return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)


# Path: tests/monte_carlo/plot.py
from frbpoppy import hist
from goodness_of_fit import GoodnessOfFit
from matplotlib.lines import Line2D
from scipy.optimize import curve_fit
from tests.convenience import plot_aa_style, rel_path
import matplotlib.pyplot as plt
import numpy as np

        self.colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
        self.gf = GoodnessOfFit()
        self.df = self.gf.so.df

        # Calculate global maximums
        self.gm = {}
        for run in self.df.run.unique():
            self.gm[run] = self.gf.calc_global_max(run)
        print(self.gm)

        # Plot various subplots
        self.alpha()
        self.si()
        self.li()
        self.li_2()
        self.lum_min()
        self.lum_max()
        self.w_int_mean()
        self.w_int_std()
        self.legend()
        self.dm_igm_slope()
        self.dm_host()
        self.axes[3, 2].set_axis_off()

        # Plot run rectangles
        # self.runs()

        # Save plot
        plt.tight_layout()  # rect=[0, 0, 0.98, 1])
        plt.subplots_adjust(wspace=0.1)

        plt.savefig(rel_path('./plots/mc/mc.pdf'))