1- # """
2- # save_plot(fig, save_path, title; data_type=".pdf")
3-
4- # Save a plot to a file.
5-
6- # # Arguments
7- # - `fig`: Plots figure object
8- # - `save_path`: Path to save the plot
9- # - `title`: Title of the plot
10- # - `data_type`: File extension (default: ".pdf")
11- # """
12- # function save_plot(fig, save_path, title; data_type=".pdf")
13- # isnothing(save_path) && throw(ArgumentError("save_path should be provided"))
1+ """
2+ save_plot(fig, save_path, title; data_type=".pdf")
3+
4+ Save a plot to a file.
5+
6+ # Arguments
7+ - `fig`: Plots figure object
8+ - `save_path`: Path to save the plot
9+ - `title`: Title of the plot
10+ - `data_type`: File extension (default: ".pdf")
11+ """
12+ function save_plot (fig, save_path, title; data_type= " .pdf" )
13+ isnothing (save_path) && throw (ArgumentError (" save_path should be provided" ))
1414
15- # !isdir(save_path) && mkpath(save_path)
16- # full_path = joinpath(save_path, title * data_type)
15+ ! isdir (save_path) && mkpath (save_path)
16+ full_path = joinpath (save_path, title * data_type)
1717
18- # @debug "Attempting to save figure to: $full_path"
19- # @debug "Current working directory: $(pwd())"
18+ @debug " Attempting to save figure to: $full_path "
19+ @debug " Current working directory: $(pwd ()) "
2020
21- # try
22- # savefig(fig, full_path)
23- # @debug "Figure saved successfully"
24-
25- # if isfile(full_path)
26- # @debug "File successfully saved to $full_path"
27- # @debug "File size: $(filesize(full_path)) bytes"
28- # else
29- # @info "File does not exist after save attempt: $full_path"
30- # end
31- # catch e
32- # @error "Error saving figure: $e"
33- # @error "Error type: $(typeof(e))"
34- # rethrow(e)
35- # end
21+ try
22+ fig. savefig (full_path)
23+ @debug " Figure saved as $data_type "
24+
25+ if isfile (full_path)
26+ @debug " File successfully saved to $full_path "
27+ @debug " File size: $(filesize (full_path)) bytes"
28+ else
29+ @info " File does not exist after save attempt: $full_path "
30+ end
31+ catch e
32+ @error " Error saving figure: $e "
33+ @error " Error type: $(typeof (e)) "
34+ rethrow (e)
35+ end
36+
37+ # if os.path.exists(full_path):
38+ # logging.debug(f"File successfully saved to {full_path}")
39+ # logging.debug(f"File size: {os.path.getsize(full_path)} bytes")
40+ # else:
41+ # logging.info(f"File does not exist after save attempt: {full_path}")
3642# end
43+ end
3744
3845"""
3946 show_plot(fig; dpi=130)
@@ -183,7 +190,7 @@ function create_geometry_plot(wing_aero, title, view_elevation, view_azimuth; zo
183190 ax. view_init (elev= view_elevation, azim= view_azimuth)
184191
185192 # Ensure the figure is fully rendered
186- fig. canvas. draw ()
193+ # fig.canvas.draw()
187194 plt. tight_layout (rect= (0 ,0 ,1 ,0.97 ))
188195
189196 return fig
@@ -203,6 +210,7 @@ function plot_geometry(wing_aero, title;
203210 view_azimuth= - 120 )
204211
205212 if is_save
213+ plt. ioff ()
206214 # Angled view
207215 fig = create_geometry_plot (wing_aero, " $(title) _angled_view" , 15 , - 120 )
208216 save_plot (fig, save_path, " $(title) _angled_view" , data_type= data_type)
@@ -221,6 +229,7 @@ function plot_geometry(wing_aero, title;
221229 end
222230
223231 if is_show
232+ plt. ion ()
224233 fig = create_geometry_plot (wing_aero, title, view_elevation, view_azimuth)
225234 plt. display (fig)
226235 end
@@ -589,7 +598,6 @@ function plot_polars(
589598 if maximum (polar_data[2 ]) > 10
590599 axs[1 , 1 ]. set_ylim ([- 0.5 , 2 ])
591600 end
592- println (label)
593601 title = raw " $C_L" * raw " $" * " vs $angle_type [°]"
594602 axs[1 , 1 ]. set_title (title)
595603 axs[1 , 1 ]. set_xlabel (" $angle_type [°]" )
@@ -630,7 +638,6 @@ function plot_polars(
630638 if maximum (polar_data[2 ]) > 10
631639 axs[1 , 2 ]. set_ylim ([- 0.5 , 2 ])
632640 end
633- println (label)
634641 title = raw " $C_D" * raw " $" * " vs $angle_type [°]"
635642 axs[1 , 2 ]. set_title (title)
636643 axs[1 , 2 ]. set_xlabel (" $angle_type [°]" )
@@ -672,7 +679,6 @@ function plot_polars(
672679 if maximum (polar_data[2 ]) > 10
673680 axs[2 , 1 ]. set_ylim ([- 0.5 , 2 ])
674681 end
675- println (label)
676682 title = raw " $C_S" * raw " $" * " vs $angle_type [°]"
677683 axs[2 , 1 ]. set_title (title)
678684 axs[2 , 1 ]. set_xlabel (" $angle_type [°]" )
@@ -714,7 +720,6 @@ function plot_polars(
714720 axs[2 , 2 ]. set_ylim ([- 0.5 , 2 ])
715721 axs[2 , 2 ]. set_xlim ([- 0.5 , 2 ])
716722 end
717- println (label)
718723 title = raw " $C_L" * raw " $" * " vs " * raw " $C_D" * raw " $"
719724 axs[2 , 2 ]. set_title (title)
720725 axs[2 , 2 ]. set_xlabel (L " $C_D$" )
@@ -724,10 +729,10 @@ function plot_polars(
724729
725730 fig. tight_layout (h_pad= 2.5 , rect= (0.01 ,0.01 ,0.99 ,0.99 ))
726731
727- # # Save and show plot
728- # if is_save
729- # save_plot(res, save_path, title, data_type=data_type)
730- # end
732+ # Save and show plot
733+ if is_save
734+ save_plot (res, save_path, title, data_type= data_type)
735+ end
731736
732737 if is_show
733738 show_plot (fig)
0 commit comments