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

[BUG] Uneven pixel spacing with heatmap in GR backend #4833

Closed
jusack opened this issue Oct 10, 2023 · 3 comments
Closed

[BUG] Uneven pixel spacing with heatmap in GR backend #4833

jusack opened this issue Oct 10, 2023 · 3 comments
Labels

Comments

@jusack
Copy link

jusack commented Oct 10, 2023

Details

When plotting a matrix of RGB colors as a heatmap for certain matrix sizes the pixel spacing of the heatmap are uneven. The severity of the unevenness depends on the size of the matrix that I am plotting. However, I could not recognize any pattern, of when the unevenness is worse.

Below is a MWE of an extreme case (the axis limits are there to see it better, they do not change the unevenness):

using Plots
gr()
heatmap(rand(RGB,300,300), xlims=(0,50), ylims=(0,50))

produces:
gr_heatmap_error

Changing the matrix size to 100x100 looks uniform. This error also does not appear when a normal Float value is used instead of a RGB value.

In the plotly backend the RGB heatmap also looks fine:
plotly_heatmap_no_error

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pythonplot x
plotlyjs x
pgfplotsx x
unicodeplots x
inspectdr x
gaston x

Versions

Plots.jl version: v1.39.0
Backend version: GR v0.72.7
Output of versioninfo():

Commit bed2cd540a (2023-08-24 14:43 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 4 on 8 virtual cores
@jusack jusack added the bug label Oct 10, 2023
@jusack
Copy link
Author

jusack commented Oct 10, 2023

Might be related to #4158

@jusack
Copy link
Author

jusack commented Oct 10, 2023

I identified the yflip parameter which is set in the following recipe as the cause of this weird scaling:

Plots.jl/src/recipes.jl

Lines 1339 to 1354 in 10ee593

@recipe function f(mat::AMat{T}) where {T<:Colorant} # COV_EXCL_LINE
n, m = map(a -> range(first(a) - 0.5, stop = last(a) + 0.5), axes(mat))
if is_seriestype_supported(:image)
seriestype := :image
yflip --> true
SliceIt, m, n, Surface(mat)
else
seriestype := :heatmap
yflip --> true
colorbar --> false
aspect_ratio --> :equal
z, plotattributes[:fillcolor] = replace_image_with_heatmap(mat)
SliceIt, m, n, Surface(z)
end
end

Another problem is, that the recipe overrides the heatmap series type to image if it is available by the backend and manually defines the x and y coordinates, circumventing the adjustment of the x and y coordinates for centered pixel bins, which is applied only to the heatmap series type in the gr backend by the function heatmap_edges.

I will look into updating the recipes for color matrices and open a PR.

@jusack
Copy link
Author

jusack commented Oct 12, 2023

The underlying issue is fixed in gr now sciapp/gr@b9eafa6 Until the fix is released in GR.jl and Plots uses the updated GR version the workaround is to explicitly set yflip=false in the call to heatmap, as it will not be overwritten by the recipe.

@jusack jusack closed this as completed Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant