-
Notifications
You must be signed in to change notification settings - Fork 164
Refactor Plots.jl integration into native package extension (#2216) #2861
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
Merged
ranocha
merged 14 commits into
trixi-framework:main
from
ShahuK283:feature/2216-plots-ext
Mar 25, 2026
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
197d455
Refactor Plots.jl integration into native package extension (#2216)
ShahuK283 8cd9b2f
Fix Plots compat bound for downgrade CI check
ShahuK283 fc3ddae
Fix method extension syntax by explicitly prefixing Trixi.
ShahuK283 c1ebfe5
Restore recipes_plots.jl include and apply Trixi formatting
ShahuK283 a6881b8
Final formatting fix and remove Plots warning
ShahuK283 cc94ff8
Update ext/TrixiPlotsExt.jl
ShahuK283 67aaa22
Update ext/TrixiPlotsExt.jl
ShahuK283 c36a7b8
Merge branch 'main' into feature/2216-plots-ext
JoshuaLampert 911a8aa
Trigger CI to fix flaky cache error
ShahuK283 30d48b3
Apply suggestion from @ranocha
ShahuK283 f90d6c5
Apply suggestion from @ranocha
ShahuK283 4d4fb4f
Update ext/TrixiPlotsExt.jl
ShahuK283 499fb00
Remove orphaned Plots warning comment
ShahuK283 9a3190c
Merge branch 'main' into feature/2216-plots-ext
ranocha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| module TrixiPlotsExt | ||
|
|
||
| # Load the required packages | ||
| using Plots: Plots | ||
| using Trixi | ||
| using Trixi: AbstractPlotData, PlotDataSeries, PlotMesh, PlotData1D, PlotData2D, | ||
| ScalarPlotData2D, PlotData2DCartesian, PlotData2DTriangulated, getmesh, | ||
| TrixiODESolution, AbstractSemidiscretization, ScalarData, DiscreteCallback, | ||
| CallbackSet, ODEProblem, ODESolution | ||
| using MuladdMacro: @muladd | ||
| using RecipesBase | ||
|
ShahuK283 marked this conversation as resolved.
Outdated
|
||
| using Printf: @sprintf | ||
|
|
||
| @muladd begin | ||
| #! format: noindent | ||
|
|
||
| function Trixi.show_plot(plot_data, variable_names; | ||
| show_mesh = true, plot_arguments = Dict{Symbol, Any}(), | ||
| time = nothing, timestep = nothing) | ||
| # Gather subplots | ||
| plots = [] | ||
| for v in variable_names | ||
| push!(plots, Plots.plot(plot_data[v]; plot_arguments...)) | ||
| end | ||
| if show_mesh | ||
| push!(plots, Plots.plot(getmesh(plot_data); plot_arguments...)) | ||
| end | ||
|
|
||
| # Note, for the visualization callback to work for general equation systems | ||
| # this layout construction would need to use the if-logic below. | ||
| # Currently, there is no use case for this so it is left here as a note. | ||
| # | ||
| # Determine layout | ||
| # if length(plots) <= 3 | ||
| # cols = length(plots) | ||
| # rows = 1 | ||
| # else | ||
| # cols = ceil(Int, sqrt(length(plots))) | ||
| # rows = div(length(plots), cols, RoundUp) | ||
| # end | ||
| # layout = (rows, cols) | ||
|
|
||
| # Determine layout | ||
| cols = ceil(Int, sqrt(length(plots))) | ||
| rows = div(length(plots), cols, RoundUp) | ||
| layout = (rows, cols) | ||
|
|
||
| # Show plot | ||
| return display(Plots.plot(plots..., layout = layout)) | ||
| end | ||
|
|
||
| function Trixi.save_plot(plot_data, variable_names; | ||
| show_mesh = true, plot_arguments = Dict{Symbol, Any}(), | ||
| time = nothing, timestep = nothing) | ||
| # Gather subplots | ||
| plots = [] | ||
| for v in variable_names | ||
| push!(plots, Plots.plot(plot_data[v]; plot_arguments...)) | ||
| end | ||
| if show_mesh | ||
| push!(plots, Plots.plot(getmesh(plot_data); plot_arguments...)) | ||
| end | ||
|
|
||
| # Determine layout | ||
| cols = ceil(Int, sqrt(length(plots))) | ||
| rows = div(length(plots), cols, RoundUp) | ||
| layout = (rows, cols) | ||
|
|
||
| # Create plot | ||
| Plots.plot(plots..., layout = layout) | ||
|
|
||
| # Determine filename and save plot | ||
| filename = joinpath("out", @sprintf("solution_%09d.png", timestep)) | ||
| return Plots.savefig(filename) | ||
| end | ||
| end # @muladd | ||
| end # module TrixiPlotsExt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.