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

Fix duplicate values on colorbar #143

Merged
merged 1 commit into from
Oct 25, 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
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ if duplicate dates are detected.
- Fix issue with plotting multiple figures at the same time.
- Improve shading for `Visualize.heatmap2D_on_globe!`.
- Add support for automatically converting CFTime.AbstractCFDateTime dates to seconds.
- Treat `NaN`s as zeros when integrating (`integrate_lon, integrate_lat, integrate_lonlat`)
- Treat `NaN`s as zeros when integrating (`integrate_lon, integrate_lat, integrate_lonlat`).
- Fix duplicate values on colorbar for plotting bias.

v0.5.10
-------
Expand Down
8 changes: 7 additions & 1 deletion ext/ClimaAnalysisGeoMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,13 @@ function Visualize.plot_bias_on_globe!(
levels = collect(range(min_level, max_level, length = nlevels))
offset = levels[argmin(abs.(levels))]
levels = levels .- offset
ticklabels = map(x -> string(round(x; digits = 0)), levels)
# log(0.1, 0.1 * (max_level - min_level)) computes the number of digits we need to round
# to (e.g. if the difference is 0.1, the digits we need to round to is 2 and if the
# difference is 0.01, then the digits we need to round to is 3)
# Take the maximum with 0 because log(0.1, 0.1 * (max_level - min_level)) is negative
# when the difference is greater than or equal to 100
digits_to_round = max(0, ceil(Int, log(0.1, 0.1 * (max_level - min_level))))
ticklabels = map(x -> string(round(x; digits = digits_to_round)), levels)
ticks = (levels, ticklabels)

default_kwargs = Dict(
Expand Down
7 changes: 6 additions & 1 deletion test/test_GeoMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ using OrderedCollections
data_zero = zeros(length(lon), length(lat))
var_zero = ClimaAnalysis.OutputVar(attribs, dims, dim_attribs, data_zero)

ClimaAnalysis.Visualize.plot_bias_on_globe!(fig6, var, var_zero)
ClimaAnalysis.Visualize.plot_bias_on_globe!(
fig6,
var,
var_zero,
cmap_extrema = (-0.001, 0.001),
)
output_name = joinpath(tmp_dir, "plot_bias.png")
Makie.save(output_name, fig6)

Expand Down