From 98c94d5c0372cb6c98ca114e6929feb485f9c7b1 Mon Sep 17 00:00:00 2001 From: Kipton Barros Date: Sat, 31 Aug 2024 12:32:08 -0600 Subject: [PATCH] Avoid Colorbar crash on empty color range (#309) --- examples/07_Dipole_Dipole.jl | 4 ++-- ext/PlottingExt.jl | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/07_Dipole_Dipole.jl b/examples/07_Dipole_Dipole.jl index e05374d30..699a63705 100644 --- a/examples/07_Dipole_Dipole.jl +++ b/examples/07_Dipole_Dipole.jl @@ -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 diff --git a/ext/PlottingExt.jl b/ext/PlottingExt.jl index f63f43c57..4006b026a 100644 --- a/ext/PlottingExt.jl +++ b/ext/PlottingExt.jl @@ -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)) @@ -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))") @@ -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 @@ -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