-
Notifications
You must be signed in to change notification settings - Fork 42
Plotting: add save plots option #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -118,7 +118,7 @@ end | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| Plot all statistics available in `output`. Additional `kwargs` are passed onto `plt.plot()` | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| function stats(output; kwargs...) | ||||||||||||||||||||||
| function stats(output; savename=nothing, savepath=pwd(), kwargs...) | ||||||||||||||||||||||
| stats = output["stats"] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| pstats = [] # pulse statistics | ||||||||||||||||||||||
|
|
@@ -160,13 +160,6 @@ function stats(output; kwargs...) | |||||||||||||||||||||
| haskey(stats, "dz") && push!(fstats, (1e6*stats["dz"], "Stepsize (μm)")) | ||||||||||||||||||||||
| haskey(stats, "core_radius") && push!(fstats, (1e6*stats["core_radius"], "Core radius (μm)")) | ||||||||||||||||||||||
| haskey(stats, "zdw") && push!(fstats, (1e9*stats["zdw"], "ZDW (nm)")) | ||||||||||||||||||||||
| haskey(stats, "mode_reconstruction_error") && push!( | ||||||||||||||||||||||
| fstats, (stats["mode_reconstruction_error"], "Mode error")) | ||||||||||||||||||||||
| haskey(stats, "transverse_points") && push!( | ||||||||||||||||||||||
| fstats, (stats["transverse_points"], "Transverse grid points")) | ||||||||||||||||||||||
| haskey(stats, "transverse_integral_error_rel") && push!( | ||||||||||||||||||||||
| fstats, (stats["transverse_integral_error_rel"], "Transverse integral error (relative)")) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| z = stats["z"]*1e2 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -187,6 +180,11 @@ function stats(output; kwargs...) | |||||||||||||||||||||
| end | ||||||||||||||||||||||
| pfig.tight_layout() | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| if savename !== nothing | ||||||||||||||||||||||
| savename1 = savename*"_1.png" | ||||||||||||||||||||||
| plt.savefig(joinpath(savepath, savename1)) | ||||||||||||||||||||||
| plt.close(pfig) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Npl = length(fstats) | ||||||||||||||||||||||
| if Npl > 0 | ||||||||||||||||||||||
|
|
@@ -203,7 +201,12 @@ function stats(output; kwargs...) | |||||||||||||||||||||
| end | ||||||||||||||||||||||
| ffig.tight_layout() | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| [pfig, ffig] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if savename !== nothing | ||||||||||||||||||||||
| savename2 = savename*"_2.png" | ||||||||||||||||||||||
| plt.savefig(joinpath(savepath, savename2)) | ||||||||||||||||||||||
| plt.close(ffig) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
Comment on lines
+205
to
+209
|
||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
Comment on lines
203
to
210
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| """ | ||||||||||||||||||||||
|
|
@@ -240,7 +243,7 @@ the sum of all modes. | |||||||||||||||||||||
| function prop_2D(output, specaxis=:f; | ||||||||||||||||||||||
| trange=(-50e-15, 50e-15), bandpass=nothing, | ||||||||||||||||||||||
| λrange=(150e-9, 2000e-9), dBmin=-60, | ||||||||||||||||||||||
| resolution=nothing, modes=nothing, oversampling=4, | ||||||||||||||||||||||
| resolution=nothing, modes=nothing, oversampling=4, savename=nothing, savepath=pwd(), | ||||||||||||||||||||||
| kwargs...) | ||||||||||||||||||||||
| z = output["z"]*1e2 | ||||||||||||||||||||||
| if specaxis == :λ | ||||||||||||||||||||||
|
|
@@ -267,6 +270,9 @@ function prop_2D(output, specaxis=:f; | |||||||||||||||||||||
| kwargs...) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
| fig | ||||||||||||||||||||||
| if savename !== nothing | ||||||||||||||||||||||
| plt.savefig(joinpath(savepath, savename)) | ||||||||||||||||||||||
| end | ||||||||||||||||||||||
|
Comment on lines
272
to
+275
|
||||||||||||||||||||||
| fig | |
| if savename !== nothing | |
| plt.savefig(joinpath(savepath, savename)) | |
| end | |
| if savename !== nothing | |
| plt.savefig(joinpath(savepath, savename)) | |
| end | |
| return fig |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time_1D now always returns nothing because the last expression is the if savename !== nothing block. The preceding sfig line does not affect the return value. Please return sfig (and only then optionally save/close), so callers can still display or further modify the figure.
| sfig | |
| if savename !== nothing | |
| plt.savefig(joinpath(savepath, savename)) | |
| plt.close(sfig) | |
| end | |
| if savename !== nothing | |
| plt.savefig(joinpath(savepath, savename)) | |
| plt.close(sfig) | |
| end | |
| return sfig |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec_1D now always returns nothing because the final expression is the if savename !== nothing block. This is a regression from returning the figure object. Please restructure so sfig is returned regardless of savename.
| sfig | |
| if savename !== nothing | |
| plt.savefig(joinpath(savepath, savename)) | |
| plt.close(sfig) | |
| end | |
| if savename !== nothing | |
| plt.savefig(joinpath(savepath, savename)) | |
| plt.close(sfig) | |
| end | |
| sfig |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spectrogram(t, Et, ...) now always returns nothing due to the if savename !== nothing block being the final expression. Please return fig regardless of saving, to preserve existing behavior.
| end | |
| end | |
| return fig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pfigis only defined whenlength(pstats) > 0, but it is unconditionally referenced in thesavename !== nothingblock. Ifpstatsis empty, callingstats(...; savename=...)will throwUndefVarError: pfig not defined. Guard the save/close withNpl > 0(orisdefined) or initializepfig = nothingand check before closing/saving.