From 8f3058af7bb0af7d8484d93496044baadadd569d Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Wed, 15 Mar 2023 18:31:35 +0100 Subject: [PATCH] Add option annotate --- Trajectories/Tests/tests.json | 5 +++-- Trajectories/plot_traj.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Trajectories/Tests/tests.json b/Trajectories/Tests/tests.json index 4959974d..9dc5acdf 100644 --- a/Trajectories/Tests/tests.json +++ b/Trajectories/Tests/tests.json @@ -116,7 +116,7 @@ "$tests_old_dir/Trajectories/expanded_traj.json", "$tests_old_dir/Cost_functions/e_overestim.txt", "$tests_old_dir/Extraction_eddies_region_2_noise/SHPC", - "Anticyclones", "--save=png" + "Anticyclones", "--save=png", "--annotate" ] }, { @@ -126,7 +126,8 @@ "$src_dir/Trajectories/plot_traj.py", "$tests_old_dir/Greece_trajectories/expanded_traj.json", "$tests_old_dir/Greece_cost_function/e_overestim.txt", - "$tests_old_dir/Greece/SHPC", "Anticyclones", "--save=png" + "$tests_old_dir/Greece/SHPC", "Anticyclones", "--save=png", + "--annotate" ] } ] diff --git a/Trajectories/plot_traj.py b/Trajectories/plot_traj.py index 645f32c1..40ea5228 100755 --- a/Trajectories/plot_traj.py +++ b/Trajectories/plot_traj.py @@ -16,6 +16,8 @@ parser.add_argument("SHPC", help = "directory") parser.add_argument("orientation", choices = ["Anticyclones", "Cyclones"]) parser.add_argument("--save", metavar = "format", help = "Save file to specified format") +parser.add_argument("--annotate", action = "store_true", help = "annotate the " + "first point of trajectory with node number") args = parser.parse_args() with open(args.expanded_traj) as f: @@ -52,10 +54,12 @@ for traj in trajectories: ax.plot(xy[:, 0], xy[:, 1], color = "red", transform = src_crs) ax.plot(xy[0, 0], xy[0, 1], marker = "s", color = "black", transform = src_crs) - ax.annotate(str(traj[0]), - ax.projection.transform_point(xy[0, 0], xy[0, 1], src_crs), - xytext = (3 * random.random(), 3 * random.random()), - textcoords = "offset points") + if args.annotate: + ax.annotate(str(traj[0]), + ax.projection.transform_point(xy[0, 0], xy[0, 1], + src_crs), + xytext = (3 * random.random(), 3 * random.random()), + textcoords = "offset points") ax.coastlines() ax.gridlines(draw_labels = True) -- GitLab