Skip to content

Update plotting support for Makie for 2D#3057

Open
vincmarks wants to merge 16 commits into
trixi-framework:mainfrom
vincmarks:plotting_support_for_Makie_2d
Open

Update plotting support for Makie for 2D#3057
vincmarks wants to merge 16 commits into
trixi-framework:mainfrom
vincmarks:plotting_support_for_Makie_2d

Conversation

@vincmarks
Copy link
Copy Markdown
Contributor

Extension of #3035 to add Makie.plot support for 2D, addressing #1872.

Changes

  • Makie.plot(sol) and Makie.plot(pd) now work for all 2D mesh types
  • Single-variable plots: Makie.plot(pd["rho"])
  • Mesh overlay: Makie.plot(pd, plot_mesh = true) or Makie.plot!(Trixi.getmesh(pd))
  • Custom axis via Makie.plot!(ax, pd["rho"])
  • Bugfix: plot_mesh kwarg in TrixiHeatmap recipe was ignored
  • Unified keyword argument: plot_mesh (was show_mesh in some functions before)
  • Tests and documentation updated

Example

trixi_include(joinpath(examples_dir(), "dgmulti_2d", "elixir_euler_curved.jl"))
pd = PlotData2D(sol)
fig = Figure()
ax = Axis(fig[1, 1], title = "Density", xlabel = "x", ylabel = "y",
          aspect = Makie.DataAspect())
plt = plot!(ax, pd["rho"], colormap = :berlin)
Colorbar(fig[1, 2], colormap = :berlin)
plot!(Trixi.getmesh(pd))
custom_axis

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Review checklist

This checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging.

Purpose and scope

  • The PR has a single goal that is clear from the PR title and/or description.
  • All code changes represent a single set of modifications that logically belong together.
  • No more than 500 lines of code are changed or there is no obvious way to split the PR into multiple PRs.

Code quality

  • The code can be understood easily.
  • Newly introduced names for variables etc. are self-descriptive and consistent with existing naming conventions.
  • There are no redundancies that can be removed by simple modularization/refactoring.
  • There are no leftover debug statements or commented code sections.
  • The code adheres to our conventions and style guide, and to the Julia guidelines.

Documentation

  • New functions and types are documented with a docstring or top-level comment.
  • Relevant publications are referenced in docstrings (see example for formatting).
  • Inline comments are used to document longer or unusual code sections.
  • Comments describe intent ("why?") and not just functionality ("what?").
  • If the PR introduces a significant change or new feature, it is documented in NEWS.md with its PR number.

Testing

  • The PR passes all tests.
  • New or modified lines of code are covered by tests.
  • New or modified tests run in less then 10 seconds.

Performance

  • There are no type instabilities or memory allocations in performance-critical parts.
  • If the PR intent is to improve performance, before/after time measurements are posted in the PR.

Verification

  • The correctness of the code was verified using appropriate tests.
  • If new equations/methods are added, a convergence test has been run and the results
    are posted in the PR.

Created with ❤️ by the Trixi.jl community.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.84%. Comparing base (2796976) to head (28a675d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3057      +/-   ##
==========================================
+ Coverage   96.83%   96.84%   +0.01%     
==========================================
  Files         636      636              
  Lines       49581    49643      +62     
==========================================
+ Hits        48011    48074      +63     
+ Misses       1570     1569       -1     
Flag Coverage Δ
unittests 96.84% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread docs/src/visualization.md Outdated
Comment on lines +476 to +478
interactive surface plots. Heatmap plots are supported for all 2D mesh types
([`TreeMesh`](@ref), [`P4estMesh`](@ref), [`UnstructuredMesh2D`](@ref), [`StructuredMesh`](@ref), [`T8codeMesh`](@ref), DGMulti meshes);
interactive surface plots are available for [`UnstructuredMesh2D`](@ref) and compatible mesh types.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to list everything here? What does "compatible mesh types" mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With "compatible mesh types" I wanted to refer to all mesh types that support iplot. While writing 3f91bd0 I noticed that iplot was actually failing for DGMulti solver due to a missing PlotData2DTriangulated constructor dispatch for DGMulti. I fixed this by adding

PlotData2DTriangulated(u, mesh, equations, dg::DGMulti{2}, cache;
kwargs...) = PlotData2D(u, mesh, equations, dg, cache; kwargs...)

to src/visualization/types.jl. This works because PlotData2D for DGMulti returns a PlotData2DTriangulated internally.

Comment thread docs/src/visualization.md
@ranocha
Copy link
Copy Markdown
Member

ranocha commented Jun 3, 2026

Thanks a lot! Please ping me when this is ready for a full review.

@vincmarks vincmarks marked this pull request as ready for review June 4, 2026 17:30
@vincmarks
Copy link
Copy Markdown
Contributor Author

@ranocha , the PR is ready for review

@ranocha ranocha added documentation Improvements or additions to documentation visualization labels Jun 4, 2026
@ranocha ranocha linked an issue Jun 4, 2026 that may be closed by this pull request
3 tasks
Copy link
Copy Markdown
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, very nice work! I have a couple of comments/questions.

Comment thread docs/src/visualization.md Outdated
both for heatmap-type plots (similar to the [Plots.jl](@ref Plots.jl) recipes) as well as for
interactive surface plots. Support is currently limited to the [`UnstructuredMesh2D`](@ref) type.
for 1D line plots and 2D heatmap-type plots (similar to the [Plots.jl](@ref Plots.jl) recipes), as well as
interactive surface plots via `iplot` for all supported 2D mesh types.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interactive surface plots via `iplot` for all supported 2D mesh types.
interactive surface plots via [`iplot`](@ref) for all supported 2D mesh types.

Comment thread docs/src/visualization.md
Comment on lines +513 to +517
With mesh lines overlaid:
```@example makie-1d
plot(pd["scalar"])
plot!(Trixi.getmesh(pd))
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we allow plot_mesh = true for oter plot types, we should do so for 1D plots as well, shouldn't we? Could you please update the code such that the following extended example works as well? Note that getmesh is exported by Trixi.jl, so we do not need to prepend it by Trixi..

Suggested change
With mesh lines overlaid:
```@example makie-1d
plot(pd["scalar"])
plot!(Trixi.getmesh(pd))
```
With mesh lines overlaid:
```@example makie-1d
plot(pd["scalar"])
plot!(getmesh(pd))
```
Alternatively, you can also pass the keyword argument `plot_mesh = true`:
```@example makie-1d
plot(pd["scalar"], plot_mesh = true)
```

Comment thread docs/src/visualization.md
Comment on lines +539 to +542
With mesh overlay:
```@example makie-2d
plot(pd, plot_mesh = true)
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With mesh overlay:
```@example makie-2d
plot(pd, plot_mesh = true)
```
With mesh overlay:
```@example makie-2d
plot(pd, plot_mesh = true)
```
Note that `plot!(getmesh(pd))` only plots the mesh in the currently active axis, e.g.,
```@example makie-2d
plot(pd)
plot!(getmesh(pd))
```

Comment thread docs/src/visualization.md Outdated
plot(pd, plot_mesh = true)
```

A key advantage of Makie over Plots.jl is the ability to compose plots on a custom axis,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A key advantage of Makie over Plots.jl is the ability to compose plots on a custom axis,
A key advantage of Makie.jl over Plots.jl is the ability to compose plots on a custom axis,

Comment thread docs/src/visualization.md Outdated
aspect = DataAspect())
plt = plot!(ax, pd["rho"], colormap = :berlin)
Colorbar(fig[1, 2], colormap = :berlin)
plot!(Trixi.getmesh(pd))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
plot!(Trixi.getmesh(pd))
plot!(getmesh(pd))

Comment thread test/test_visualization.jl Outdated

# single-variable plot with axis and colorbar (works for all PlotData2DTriangulated meshes)
pd = PlotData2D(sol)
fap = Makie.plot(pd["rho"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fap = Makie.plot(pd["rho"])
fap = @trixi_test_nowarn Makie.plot(pd["rho"])

Comment thread test/test_visualization.jl Outdated
@trixi_test_nowarn Makie.plot(pd["rho"], plot_mesh = true)

# explicit PlotMesh overlay (works for all PlotData2DTriangulated meshes)
Makie.plot(pd["rho"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Makie.plot(pd["rho"])
@trixi_test_nowarn Makie.plot(pd["rho"])

Comment thread test/test_visualization.jl Outdated
# explicit PlotMesh overlay (works for all PlotData2DTriangulated meshes)
Makie.plot(pd["rho"])
@trixi_test_nowarn Makie.plot!(Trixi.PlotMesh(pd))
Makie.plot(pd["rho"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Makie.plot(pd["rho"])
@trixi_test_nowarn Makie.plot(pd["rho"])

Comment thread test/test_visualization.jl Outdated

# explicit PlotMesh overlay (works for all PlotData2DTriangulated meshes)
Makie.plot(pd["rho"])
@trixi_test_nowarn Makie.plot!(Trixi.PlotMesh(pd))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@trixi_test_nowarn Makie.plot!(Trixi.PlotMesh(pd))
@trixi_test_nowarn Makie.plot!(getmesh(pd))

Comment thread test/test_visualization.jl Outdated
Makie.plot(pd["rho"])
@trixi_test_nowarn Makie.plot!(Trixi.PlotMesh(pd))
Makie.plot(pd["rho"])
@trixi_test_nowarn Makie.plot!(Trixi.PlotMesh(pd), color = :black,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@trixi_test_nowarn Makie.plot!(Trixi.PlotMesh(pd), color = :black,
@trixi_test_nowarn Makie.plot!(getmesh(pd), color = :black,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation visualization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update plotting support for Makie to preferred Makie workflow

2 participants