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

Avoid Colorbar crash on empty color range #309

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/07_Dipole_Dipole.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ res3 = intensities_bands(swt, path)
# slight corrections are needed for the third dispersion band.

fig = Figure(size=(768, 300))
plot_intensities!(fig[1, 1], res1; units, title="Local Exchange Only")
ax = plot_intensities!(fig[1, 2], res2; units, title="Local Exchange and Dipole-Dipole")
plot_intensities!(fig[1, 1], res1; units, title="Without long-range dipole")
ax = plot_intensities!(fig[1, 2], res2; units, title="With long-range dipole")
for c in eachrow(res3.disp)
lines!(ax, eachindex(c), c; linestyle=:dash, color=:black)
end
Expand Down
8 changes: 4 additions & 4 deletions ext/PlottingExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ function Sunny.plot_intensities!(panel, res::Sunny.Intensities{Float64}; colorma
xticklabelrotation = maximum(length.(qpts.xticks[2])) > 3 ? π/6 : 0.0
ax = Makie.Axis(panel[1, 1]; xlabel="Momentum (r.l.u.)", ylabel, qpts.xticks, xticklabelrotation, axisopts...)
hm = Makie.heatmap!(ax, axes(data, 2), collect(energies/unit_energy), data'; colormap, colorrange)
Makie.Colorbar(panel[1, 2], hm)
allequal(colorrange) || Makie.Colorbar(panel[1, 2], hm)
return ax
elseif qpts isa Sunny.QGrid{2}
if isone(length(energies))
Expand All @@ -1123,7 +1123,7 @@ function Sunny.plot_intensities!(panel, res::Sunny.Intensities{Float64}; colorma
(xs, ys) = map(range, qpts.coefs_lo, qpts.coefs_hi, size(qpts.qs))
ax = Makie.Axis(panel[1, 1]; xlabel, ylabel, aspect, axisopts...)
hm = Makie.heatmap!(ax, xs, ys, dropdims(data; dims=1); colormap, colorrange)
Makie.Colorbar(panel[1, 2], hm)
allequal(colorrange) || Makie.Colorbar(panel[1, 2], hm)
return ax
else
error("Cannot yet plot $(typeof(res))")
Expand All @@ -1147,7 +1147,7 @@ function Sunny.plot_intensities!(panel, res::Sunny.StaticIntensities{Float64}; c
(xs, ys) = map(range, qpts.coefs_lo, qpts.coefs_hi, size(qpts.qs))
ax = Makie.Axis(panel[1, 1]; xlabel, ylabel, aspect, axisopts...)
hm = Makie.heatmap!(ax, xs, ys, data; colormap, colorrange)
Makie.Colorbar(panel[1, 2], hm)
allequal(colorrange) || Makie.Colorbar(panel[1, 2], hm)
return ax
elseif qpts isa Sunny.QPath
xticklabelrotation = maximum(length.(qpts.xticks[2])) > 3 ? π/6 : 0.0
Expand All @@ -1171,7 +1171,7 @@ function Sunny.plot_intensities!(panel, res::Sunny.PowderIntensities{Float64}; c

ax = Makie.Axis(panel[1, 1]; xlabel, ylabel, axisopts...)
hm = Makie.heatmap!(ax, res.radii, collect(res.energies/unit_energy), res.data'; colormap, colorrange)
Makie.Colorbar(panel[1, 2], hm)
allequal(colorrange) || Makie.Colorbar(panel[1, 2], hm)
return ax
end

Expand Down
Loading