From 1ebb6e080bc8a9eb4fd0010085dbb43c1dcdc0c5 Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ipsl.fr>
Date: Mon, 21 Oct 2024 18:13:50 +0200
Subject: [PATCH] Move saving to main part of the script

---
 Inst_eddies/Analysis/plot_velocity.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/Inst_eddies/Analysis/plot_velocity.py b/Inst_eddies/Analysis/plot_velocity.py
index 7b343d53..88a9f08b 100755
--- a/Inst_eddies/Analysis/plot_velocity.py
+++ b/Inst_eddies/Analysis/plot_velocity.py
@@ -89,12 +89,7 @@ def plot_velocity(args):
 
     ax.gridlines(draw_labels=True)
     ax.coastlines()
-
-    if args.save:
-        fig.savefig(f"plot_velocity.{args.save}")
-        print(f'Created "plot_velocity.{args.save}".')
-    else:
-        plt.show()
+    return fig
 
 
 if __name__ == "__main__":
@@ -129,4 +124,10 @@ if __name__ == "__main__":
     )
     parser.add_argument("input_file", help="NetCDF file containing velocity")
     args = parser.parse_args()
-    plot_velocity(args)
+    fig = plot_velocity(args)
+
+    if args.save:
+        fig.savefig(f"plot_velocity.{args.save}")
+        print(f'Created "plot_velocity.{args.save}".')
+    else:
+        plt.show()
-- 
GitLab