From 5656b96545d9681c045e8b3721bbc64761365b09 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Fri, 20 Jul 2018 07:05:48 +1000 Subject: [PATCH] Add label showing most recent volume change --- las_outputs.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/las_outputs.py b/las_outputs.py index 1f3632c..2e3aed3 100644 --- a/las_outputs.py +++ b/las_outputs.py @@ -35,7 +35,7 @@ def remove_temp_files(directory): return None -def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits): +def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, delta_vol): csv_name = profile_name + '.csv' profiles = pd.read_csv(os.path.join(csv_output_dir, csv_name)) @@ -55,7 +55,12 @@ def plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits): ax.set_xlabel('Chainage (m)', labelpad=10) ax.set_ylabel('Elevation (m AHD)', labelpad=10) - ax.legend(frameon=False, fontsize=9) + + # Show most recent volume change + ax.annotate('Most recent\nvolume change:\n{:0.1f} m$^3$/m'.format(delta_vol), + (0.1, 0.15), xycoords='axes fraction', fontsize=8, + backgroundcolor='#ffffff', linespacing=1.5) + ax.legend(edgecolor='none', facecolor='#ffffff', fontsize=9) ax.xaxis.set_minor_locator(MultipleLocator(5)) ax.yaxis.set_minor_locator(MultipleLocator(0.5)) @@ -99,9 +104,17 @@ def calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volu volumes.loc[profile_name, date] = volume # Save updated volumes spreadsheet + volumes = volumes[volumes.columns.sort_values()] volumes = volumes.sort_index() volumes.to_csv(csv_vol) + # Get most recent volume difference for current profile + previous_vol = volumes.loc[profile_name].values[-2] + current_vol = volumes.loc[profile_name].values[-1] + delta_vol = current_vol - previous_vol + + return delta_vol + def main(): parser = argparse.ArgumentParser() @@ -191,8 +204,11 @@ def main(): print('Updating figures...') profile_names = df['Profile'].unique() for profile_name in profile_names: - plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits) - calculate_volumes(profile_name, survey_date, csv_output_dir, ch_limits, volume_output_dir) + delta_vol = calculate_volumes(profile_name, survey_date, + csv_output_dir, ch_limits, + volume_output_dir) + plot_profiles(profile_name, csv_output_dir, graph_loc, ch_limits, + delta_vol) # Remove temprary files remove_temp_files(tmp_dir) @@ -200,3 +216,7 @@ def main(): if __name__ == '__main__': main() + +if True: + plt.plot([], label='label') + plt.legend(facecolor='r')