-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
[WIP] Add a very basic Makie extension #611
Conversation
Currently only works for AbstractTimeseriesSolutions, and only plots line plots.
This allows their values to be passed through from higher level recipes/the user without requiring intensive computation.
Integrators have a recipe as well |
Cycling only works by variable (and is forced for now). Will have to see how to fix that in future!
I think this looks good? |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #611 +/- ##
==========================================
- Coverage 40.16% 38.91% -1.26%
==========================================
Files 54 55 +1
Lines 4133 4266 +133
==========================================
Hits 1660 1660
- Misses 2473 2606 +133 ☔ View full report in Codecov by Sentry. |
It should work for most simple usecases - more advanced ones will probably need to be deconstructed manually, but that's not particularly hard... |
That's fine, it's a start. We can get it in there and let it keep improving. |
I have a question about the recipe, but I am not sure if this is the right place to ask @asinghvi17 . Say if I want to scale the axis (e.g. time) by a factor of 10 for plotting, how should I do that? Makie provides a function f = Figure()
ax = Axis(f[1, 1], aspect=1)
l0 = lines!(ax, [0, 1], [0, 1])
scale!(l0, 10, 1) but not for the DiffEq recipe: using OrdinaryDiffEq
using GLMakie
function lorenz(du,u,p,t)
du[1] = p[1]*(u[2]-u[1])
du[2] = u[1]*(p[2]-u[3]) - u[2]
du[3] = u[1]*u[2] - p[3]*u[3]
end
u0 = [1., 5., 10.]
tspan = (0., 100.)
p = (10.0,28.0,8/3)
prob = ODEProblem(lorenz, u0, tspan,p)
sol = solve(prob, Tsit5())
f, a, p = plot(sol)
axislegend(a)
# This is not working!
scale!(p, 10, 1)
f |
Ah! I think this is another issue uncovered - the API I used to do this is still pretty new! You can of course scale the plots individually, by inspecting e.g. Would you mind filing an issue on the Makie repo, @henry2004y? |
Sure! Hopefully there will be a quick fix. Thanks for the new recipe! |
And another maybe related issue is that the new recipe does not work with plotting attributes (e.g. MWEusing OrdinaryDiffEq
using GLMakie
function lorenz(du,u,p,t)
du[1] = p[1]*(u[2]-u[1])
du[2] = u[1]*(p[2]-u[3]) - u[2]
du[3] = u[1]*u[2] - p[3]*u[3]
end
u0 = [1., 5., 10.]
tspan = (0., 100.)
p = (10.0,28.0,8/3)
prob = ODEProblem(lorenz, u0, tspan,p)
sol = solve(prob, Tsit5())
f, a, p = lines(sol, linestyle=:dot) |
Same issue unfortunately :( |
Is there a temporary workaround for attributes before it's properly fixed in Makie? |
Honestly I am now pretty frustrated about the new SpecAPI introduced in Makie v0.20. The old approaches for creating recipes did not limit it capability in so many ways. Here is yet another issue with MWEusing OrdinaryDiffEq
using GLMakie
function lorenz(du,u,p,t)
du[1] = p[1]*(u[2]-u[1])
du[2] = u[1]*(p[2]-u[3]) - u[2]
du[3] = u[1]*u[2] - p[3]*u[3]
end
u0 = [1., 5., 10.]
tspan = (0., 100.)
p = (10.0,28.0,8/3)
prob = ODEProblem(lorenz, u0, tspan,p)
sol = solve(prob, Tsit5())
fig = Figure()
ax = Axis(fig[1, 1])
t1, t2 = 0.0, 100.0
step = (t2 - t1) / 1e3
time_format = t2 < 2e-3 ? "{:.3e} s" : "{:.3f} s"
# the minimum of the range cannot be t1.
sg = SliderGrid(fig[2, 1],
(label="Time",
range=range(t1+step, stop=t2, step=step),
format=time_format,
startvalue=t2))
# convert tspan to an Observable
tspan = lift(sg.sliders[1].value) do t
(t1, t)
end
lines!(ax, sols; idxs=1, tspan)
# Drag the slider and errors pop out! Do you think it's possible to switch back to the more stable APIs for now and switch to the newer experimental Makie APIs once it becomes mature? @asinghvi17 Another issue related to this recipe but maybe not to Makie itself: following the way fig, ax, pl = lines(sol, idxs=(1,2,3)) is supposed to plot a 3D figure. However, now in Makie it only shows a 2D figure. If I want a 3D figure, I would need to do f = Figure()
ax = Axis3(f[1, 1],
aspect = :data,
)
lines!(ax, sol; idxs=(1,2,3)) |
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
I thought I'd update the code in #427 for the latest Makie, and while I was at it made it an extension as well.
This doesn't work fully yet, in that:
plot
, likelinewidth
. Setting that theme externally still works, though.