Skip to content

Commit

Permalink
Avoid Colorbar crash on empty color range (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros authored Aug 31, 2024
1 parent 3c07e7d commit 98c94d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 98c94d5

Please sign in to comment.