Skip to content

Commit

Permalink
Fix contourf level calculation (#3713)
Browse files Browse the repository at this point in the history
* make upper band inclusive for n contourf limits

* add reftest

* add changelog

* length keyword
  • Loading branch information
jkrumbiegel authored Mar 18, 2024
1 parent 3afefb4 commit 88ffa6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added supported markers hint to unsupported marker warn message [#3666](https://github.com/MakieOrg/Makie.jl/pull/3666).
- Fixed bug in CairoMakie line drawing when multiple successive points had the same color [#3712](https://github.com/MakieOrg/Makie.jl/pull/3712).
- Remove StableHashTraits in favor of calculating hashes directly with CRC32c [#3667](https://github.com/MakieOrg/Makie.jl/pull/3667).
- Fixed `contourf` bug where n levels would sometimes miss the uppermost value, causing gaps [#3713](https://github.com/MakieOrg/Makie.jl/pull/3713).

## [0.20.8] - 2024-02-22

Expand Down
12 changes: 12 additions & 0 deletions ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1392,3 +1392,15 @@ end
ylims!(ax, 0, 1)
fig
end

@reference_test "contourf bug #3683" begin
x = y = LinRange(0, 1, 4)
ymin, ymax = 0.4, 0.6
steepness = 0.1
f(x, y) = (tanh((y - ymin) / steepness) - tanh((y - ymax) / steepness) - 1)
z = [f(_x, _y) for _x in x, _y in y]

fig, ax, cof = contourf(x, y, z, levels = 2)
Colorbar(fig[1, 2], cof)
fig
end
6 changes: 3 additions & 3 deletions src/basic_recipes/contourf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end
# _computed_extendlow
# _computed_extendhigh

_get_isoband_levels(levels::Int, mi, ma) = Float32.(LinRange(mi, ma, levels+1))
_get_isoband_levels(levels::Int, mi, ma) = collect(range(Float32(mi), nextfloat(Float32(ma)), length = levels+1))

function _get_isoband_levels(levels::AbstractVector{<:Real}, mi, ma)
edges = Float32.(levels)
Expand Down Expand Up @@ -84,12 +84,12 @@ function Makie.plot!(c::Contourf{<:Tuple{<:AbstractVector{<:Real}, <:AbstractVec
lowcolor = Observable{RGBAf}()
map!(compute_lowcolor, c, lowcolor, c.extendlow, c.colormap)
c.attributes[:_computed_extendlow] = lowcolor
is_extended_low = lift(!isnothing, c, lowcolor)
is_extended_low = lift(!isnothing, c, c.extendlow)

highcolor = Observable{RGBAf}()
map!(compute_highcolor, c, highcolor, c.extendhigh, c.colormap)
c.attributes[:_computed_extendhigh] = highcolor
is_extended_high = lift(!isnothing, c, highcolor)
is_extended_high = lift(!isnothing, c, c.extendhigh)
PolyType = typeof(Polygon(Point2f[], [Point2f[]]))

polys = Observable(PolyType[])
Expand Down

0 comments on commit 88ffa6e

Please sign in to comment.