def plot22(obs, sim, colname, energies=[[300, 1000], [1000, 2000]]): """Place 2*2 piecharts on a figure. Parameters ---------- obs : `astropy.table.Table` Observed events sim : `astropy.table.Table` Events simulated with MARX energies : list Two energy bands in eV defined as a list of lists. Returns ------- fig : `matplotlib.figure.Figure` Figure with plot """ fig = plt.figure(figsize=(7, 7)) for i, data in enumerate([obs, sim]): for j, en in enumerate(energies): ax = fig.add_subplot(2, 2, i * 2 + j + 1, aspect="equal") obssimlab = "Obs" if i == 0 else "MARX" energylab = "{0} - {1} eV".format(en[0], en[1]) ax.set_title("{0}: {1}".format(obssimlab, energylab)) energy = colname_case(data, "energy") plotpie(ax, data[(energy > en[0]) & (energy < en[1])], colname) return fig
def plotpie(ax, data, col, colors=["r", "c", "m", "orange", "g"], **plotargs): """Bin up events data and display in pie chart""" counts = np.bincount(colname_case(data, col)) labels = np.arange(len(counts)) ind = counts > 0 ax.pie(counts[ind], labels=labels[ind], colors=colors, autopct="%2i%%", **plotargs)