def time_series_plot(df, extra_plots=[], column_name='hmix', ysc=1, do_flight_data=True, ax=None, draw_legend=True): """ plot dfsummary (above), based on the function in draw_figures.py """ #res = np.diff(df.index.to_pydatetime())[0].total_seconds() # make a custom legend handler to get the error range into the legend # ref: http://matplotlib.org/users/legend_guide.html#proxy-legend-handles class HardWiredHandler(object): def legend_artist(self, legend, orig_handle, fontsize, handlebox): x0, y0 = handlebox.xdescent, handlebox.ydescent width, height = handlebox.width, handlebox.height patch = mpl.patches.Rectangle([x0, y0], width, height, facecolor='k', alpha=0.2, edgecolor='none', transform=handlebox.get_transform()) line = mpl.lines.Line2D([x0, x0+width], [y0+height/2.0, y0+height/2.0], color='k',solid_capstyle='butt', linewidth=1.5, transform=handlebox.get_transform()) handlebox.add_artist(patch) handlebox.add_artist(line) return patch if ax is None: fig, ax = figure_template('acp-1') else: fig = ax.figure # draw a plot with pandas to configure ax using pandas' date formatting # df.lld.plot(ax=ax) # del ax.lines[0] #ysc = 1.0/res t = df.index low = df[column_name+'_p16'].values #_p16 or _p10 #low[low<10] = 10 # prevent zeros # print(low.min()) high = df[column_name+'_p84'].values #_p84 or _p90 r1 = ax.fill_between(t, low*ysc, high*ysc, alpha=0.2, color='k', linewidth=0) # for debugging # ax.plot(t, low*ysc, color='k', alpha=0.2) # ax.plot(t, high*ysc, color='k', alpha=0.2) r2 = ax.plot(t, df[column_name+'_mean'].values*ysc, 'k') leg_objs = [] leg_entries = [] leg_objs.append((r1,r2)) leg_entries.append('Box model with BMC deconvolution') ret = ax.plot(t, df[column_name+'_scaled']*ysc)[0] leg_objs.append(ret) leg_entries.append('Box model with raw detector output') ret = ax.plot(t, df[column_name+'_scaled_shifted']*ysc)[0] leg_objs.append(ret) leg_entries.append('Box model with lagged detector output') if do_flight_data: #x,y = 2011-11-06 07:56:59.650000 671.056073212 # (from 2014-10-goulburn-sbl-fluxes/extract_and_plot_soundings.py) x = datetime.datetime(2011,11,6,8,0) y = np.array([[583,671], [206,651]]) x = datetime.datetime(2011,11,6,8,0), datetime.datetime(2011,11,6,7,25) ret = ax.errorbar(x, y.mean(axis=1), yerr=np.diff(y, axis=1).ravel()/2.0, fmt='none') leg_objs.append(ret) leg_entries.append('Aircraft measurements') for xdata, ydata, label in extra_plots: ret = ax.plot(xdata, ydata)[0] leg_objs.append(ret[0]) leg_entries.append(label) # make the legend if draw_legend: ax.legend(leg_objs, leg_entries, handler_map={tuple: HardWiredHandler()}, loc='upper left', frameon=False) # format x-axis #from micromet.plot import day_ticks #day_ticks(ax) # TODO: switch to pandas convention ax.xaxis.set_major_formatter(mpl.dates.DateFormatter('%H:%M')) fancy_ylabel(ax, 'Boundary layer depth (m)') return fig, ax
def newfig(): fig, ax = figure_template('acp-1') return fig, ax
elif pos == 'right': ann = ax.annotate(s,xy=(1,1), xycoords='axes fraction', textcoords='offset points', xytext=(28+hoffset, 10), fontsize=textsize, horizontalalignment='right') return ann xvar = 'relhum' yvar = 'a_to_c' data = [] positions = [] for day_number, dfchain in chains_by_day: dfss = peaklist[day_number-1] data.append(dfchain[k].values) positions.append(dfss[xvar][:60].mean()) fig, ax = figure_template('acp-1') ax.boxplot(data, positions=positions, showfliers=False, showcaps=False, boxprops=dict(color="#0072B2"), medianprops=dict(color="#0072B2")) ax.xaxis.set_major_locator(mpl.ticker.AutoLocator()) ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.set_xlabel('Relative humidity (%)') fancy_ylabel(ax, 'Polonium-218 counts / Polonium-214 counts') savefig(fig, 'bayes-fit-to-peaks-relh-versus-po-count-ratio-boxplot', fdir='./figures/') # error bar plot version yplt = [np.mean(itm) for itm in data] yerr = [np.std(itm) for itm in data] fig, ax = figure_template('acp-1')