Skip to content
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

Use Makie.automatic for colorrange #120

Merged
merged 3 commits into from
Apr 10, 2024

Conversation

KnutAM
Copy link
Member

@KnutAM KnutAM commented Feb 14, 2024

supersedes #119, thanks for the tip @termi-official on Makie.automatic (haven't checked if this introduces new compat requirements)

Reproducer

using Ferrite, FerriteViz
import GLMakie as Plt

grid = generate_grid(Quadrilateral, (2, 2))

dh = DofHandler(grid)
add!(dh, :u, 1, Lagrange{2,RefCube,1}())
close!(dh)

a = zeros(ndofs(dh))

apply_analytical!(a, dh, :u, x -> rand() - 0.5) # ∈ [-0.5, 0.5]

plotter = MakiePlotter(dh, a)

fig = Plt.Figure()
ax = Plt.Axis(fig[1,1])
sp = solutionplot!(ax, plotter; colorrange=(-1.0, 1.0))
Plt.Colorbar(fig[1,2], sp)
fig

master (colorrange [-1, 1] not respected):
master

pr (colorrange [-1, 1] respected)
pr

@koehlerson
Copy link
Member

Can we add this for all plot types?

I think it's just CellPlot that needs to be changed too

CP[:colorrange] = @lift(isapprox($mins,$maxs) ? ($mins,1.01($maxs)) : ($mins,$maxs))

@termi-official
Copy link
Member

Does this work if min approx max and min or max approx zero? We introduced the fix back then, because the automatic colorrange failed to display at all in these cases.

@koehlerson
Copy link
Member

ah misread the PR example, I thought it display $[-1,-1]$ and thought that it can handle this now. But yeah this would be good to test

@KnutAM
Copy link
Member Author

KnutAM commented Feb 14, 2024

Does this work if min approx max and min or max approx zero? We introduced the fix back then, because the automatic colorrange failed to display at all in these cases.

It seems to work, but gives the warning (4 times)

┌ Warning: No strict ticks found
└ @ PlotUtils C:\Users\meyer\.julia\packages\PlotUtils\jEGKP\src\ticks.jl:191
using Ferrite, FerriteViz
import GLMakie as Plt

grid = generate_grid(Quadrilateral, (2, 2))

dh = DofHandler(grid)
add!(dh, :u, 1, Lagrange{2,RefCube,1}())
close!(dh)

a = zeros(ndofs(dh))

apply_analytical!(a, dh, :u, x -> rand() - 0.5) # ∈ [-0.5, 0.5]

plotter = MakiePlotter(dh, a)

fig = Plt.Figure()
ax = Plt.Axis(fig[1,1])
sp = solutionplot!(ax, plotter; colorrange=(-1.0, 1.0))
Plt.Colorbar(fig[1,2], sp)
fig

# Case with zero amplitude of data
apply_analytical!(a, dh, :u, Returns(0.0))
p2 = MakiePlotter(dh, a)
ax2 = Plt.Axis(fig[2,1])
sp2 = solutionplot!(ax2, p2)
Plt.Colorbar(fig[2,2], sp2)

# Case with almost zero amplitude of data (works but warns)
apply_analytical!(a, dh, :u, x -> 1e-20*rand())
p3 = MakiePlotter(dh, a)
ax3 = Plt.Axis(fig[3,1])
sp3 = solutionplot!(ax3, p2)
Plt.Colorbar(fig[3,2], sp3)

fig

mwe

@termi-official
Copy link
Member

Does this work if min approx max and min or max approx zero? We introduced the fix back then, because the automatic colorrange failed to display at all in these cases.

using Ferrite, FerriteViz
import GLMakie as Plt

grid = generate_grid(Quadrilateral, (2, 2))

dh = DofHandler(grid)
add!(dh, :u, 1, Lagrange{2,RefCube,1}())
close!(dh)

a = zeros(ndofs(dh))

plotter = MakiePlotter(dh, a)

fig = Plt.Figure()
ax = Plt.Axis(fig[1,1])
sp = solutionplot!(ax, plotter)
Plt.Colorbar(fig[1,2], sp)
fig
using Ferrite, FerriteViz
import GLMakie as Plt

grid = generate_grid(Quadrilateral, (2, 2))

dh = DofHandler(grid)
add!(dh, :u, 1, Lagrange{2,RefCube,1}())
close!(dh)

a = ones(ndofs(dh))

plotter = MakiePlotter(dh, a)

fig = Plt.Figure()
ax = Plt.Axis(fig[1,1])
sp = solutionplot!(ax, plotter)
Plt.Colorbar(fig[1,2], sp)
fig
using Ferrite, FerriteViz
import GLMakie as Plt

grid = generate_grid(Quadrilateral, (2, 2))

dh = DofHandler(grid)
add!(dh, :u, 1, Lagrange{2,RefCube,1}())
close!(dh)

a = rand(ndofs(dh))

plotter = MakiePlotter(dh, a)

fig = Plt.Figure()
ax = Plt.Axis(fig[1,1])
sp = solutionplot!(ax, plotter)
Plt.Colorbar(fig[1,2], sp)
fig

All work now with the automatic keyword (at least on the latest Makie release). 🚀

Can you add the corresponding change also to CellPlot as Max proposed. And add the information to the docstrings, because it seems this option is missing. Thanks!

@termi-official
Copy link
Member

I have locally a fix to recover the NaN handling. If @koehlerson is fine with the changes I will push, we make another round of review and merge.

@koehlerson koehlerson merged commit 9278bd1 into Ferrite-FEM:master Apr 10, 2024
6 checks passed
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.

None yet

3 participants