Skip to content

Fix Makie recipe to support 3D plots with automatic LScene detection #1079

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChrisRackauckas
Copy link
Member

Summary

  • Fixes Makie recipe does not support 3D output #947 by adding preferred_axis_type methods for SciML solution types
  • Automatically detects when 3D plotting is requested (idxs=(1,2,3)) and returns LScene as the preferred axis type
  • Maintains backward compatibility by defaulting to regular Axis for 2D plots

The Problem

When plotting a 3D system using the Makie recipe with idxs = (1, 2, 3), the plot fails because Makie defaults to a 2D Axis instead of using LScene for 3D visualizations. Users had to manually specify axis = (; type = LScene) as a workaround.

The Solution

Added preferred_axis_type methods for:

  • AbstractTimeseriesSolution
  • DEIntegrator
  • AbstractEnsembleSolution

These methods check if idxs (or the deprecated vars) parameter contains exactly 3 indices, and if so, return Makie.LScene as the preferred axis type. Otherwise, they default to Makie.Axis.

Test plan

  • Tested the fix with the MRE from issue Makie recipe does not support 3D output #947
  • Verified that 2D plots still work correctly with regular Axis
  • Verified that manual axis specification still works
  • Checked that both tuple and array forms of idxs are handled

🤖 Generated with Claude Code

This commit adds `preferred_axis_type` methods for AbstractTimeseriesSolution,
DEIntegrator, and AbstractEnsembleSolution that automatically detect when
3D plotting is requested (idxs=(1,2,3)) and return LScene as the preferred
axis type instead of the default Axis.

This fixes issue #947 where 3D plots failed because Makie defaulted to
2D Axis instead of using LScene for 3D visualizations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
# Define preferred axis type based on the idxs parameter
function Makie.preferred_axis_type(plot::Plot{<:Tuple{<:SciMLBase.AbstractTimeseriesSolution}})
if haskey(plot, :idxs) || haskey(plot, :vars)
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
idxs = haskey(plot, :idxs) ? plot[:idxs][] :
(haskey(plot, :vars) ? plot[:vars][] : nothing)

if idxs isa Tuple && length(idxs) == 3
return Makie.LScene
elseif idxs isa AbstractArray && length(idxs) == 3
return Makie.LScene
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return Makie.LScene
return Makie.LScene

# Define preferred axis type for integrator plots
function Makie.preferred_axis_type(plot::Plot{<:Tuple{<:SciMLBase.DEIntegrator}})
if haskey(plot, :idxs) || haskey(plot, :vars)
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
idxs = haskey(plot, :idxs) ? plot[:idxs][] :
(haskey(plot, :vars) ? plot[:vars][] : nothing)

if idxs isa Tuple && length(idxs) == 3
return Makie.LScene
elseif idxs isa AbstractArray && length(idxs) == 3
return Makie.LScene
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return Makie.LScene
return Makie.LScene

# Define preferred axis type for ensemble plots
function Makie.preferred_axis_type(plot::Plot{<:Tuple{<:SciMLBase.AbstractEnsembleSolution}})
if haskey(plot, :idxs) || haskey(plot, :vars)
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
idxs = haskey(plot, :idxs) ? plot[:idxs][] : (haskey(plot, :vars) ? plot[:vars][] : nothing)
idxs = haskey(plot, :idxs) ? plot[:idxs][] :
(haskey(plot, :vars) ? plot[:vars][] : nothing)

if idxs isa Tuple && length(idxs) == 3
return Makie.LScene
elseif idxs isa AbstractArray && length(idxs) == 3
return Makie.LScene
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return Makie.LScene
return Makie.LScene

@ChrisRackauckas
Copy link
Member Author

@asinghvi17 can you look at this one?

@@ -23,6 +23,19 @@ function ensure_plottrait(PT::Type, arg, desired_plottrait_type::Type)
end
end

# Define preferred axis type based on the idxs parameter
function Makie.preferred_axis_type(plot::Plot{<:Tuple{<:SciMLBase.AbstractTimeseriesSolution}})
Copy link
Contributor

Choose a reason for hiding this comment

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

This dispatch doesn't actually do anything. I don't think you can actually hook into this in this way in Makie v0.24. It might need a small patch, I'm PRing that to Makie now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Makie recipe does not support 3D output
3 participants