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

heatmap + colormap=Makie.Categorical results in incorrect colorrange #3827

Closed
3 tasks done
musoke opened this issue May 6, 2024 · 6 comments
Closed
3 tasks done

heatmap + colormap=Makie.Categorical results in incorrect colorrange #3827

musoke opened this issue May 6, 2024 · 6 comments
Labels

Comments

@musoke
Copy link
Contributor

musoke commented May 6, 2024

  • are you running newest version (version from docs) ?

  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)

    • yes
  • What platform + GPU are you on?

    • GPU: NVIDIA RTX A3000
    • versioninfo():
Julia Version 1.10.3
Commit 0b4590a5507 (2024-04-30 10:59 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
Threads: 16 default, 0 interactive, 8 GC (on 16 virtual cores)
Environment:
  LD_LIBRARY_PATH = /snap/alacritty/70/usr/lib/x86_64-linux-gnu:/snap/alacritty/70/lib/x86_64-linux-gnu:/snap/alacritty/70/usr/lib/x86_64-linux-gnu/dri
  JULIA_NUM_THREADS = auto

I was attempting to use the experimental categorical colorbars and found some incorrect behavior.

I ran the following to set up a fresh environment

using Pkg
Pkg.activate(temp=true)
Pkg.add(["Makie", "CairoMakie"])
Pkg.status()
using CairoMakie
Status `/tmp/jl_c9NOuT/Project.toml`
  [13f3f980] CairoMakie v0.11.10
  [ee78f7c6] Makie v0.20.9

The following code without a categorical colorbar results in a figure as expected:

fig, ax, pl = heatmap(1:3, 1:3, .-(1:3))
Colorbar(fig[1, 2], pl)
fig

image

However, using colormap=Makie.Categorical results in a colorbar whose colorrange does not correspond to the data range.

fig, ax, pl = heatmap(1:3, 1:3, .-(1:3), colormap=Makie.Categorical(:viridis))
Colorbar(fig[1, 2], pl)
fig

image
The colorbar is labeled from 1 to 4, none of which appear in the data.

@musoke musoke added the bug label May 6, 2024
@asinghvi17
Copy link
Member

#3762 should fix this.

@musoke
Copy link
Contributor Author

musoke commented May 6, 2024

Cool!
I'll retry when 0.20.10 is released

@SimonDanisch
Copy link
Member

On 0.20.10 this happens:
image

I think this is correct, since the transparent values are done by inserting NaNs....
It could be a bit confusing though since the user didn't input any NaNs. The only fix I can think of would be not creating the "sparse" heatmap from 3 vectors via NaNs but rather with a scatter plot or so... But that'd be a relatively big change

@musoke
Copy link
Contributor Author

musoke commented May 6, 2024

That colorbar is pretty close to what I would have expected.
I agree that this handling of "sparse" data is not ideal. Would it be possible to remove the NaN category from the colorbar after the fact? Or internally use missing instead of NaN for such cases?

It might be helpful for you to know more about my actual use case: I have an Enum and am plotting a heatmap where the colors correspond to enum instances. I was originally doing this with a scatter plot but there are many points, so a heatmap is more readable. I can writeup a MWE in another issue if that would be helpful.

@musoke
Copy link
Contributor Author

musoke commented May 6, 2024

How does colorrange work with categorical colorbars? Especially in cases where the categories are not ordered or a category is not in the data but should appear on the axis.

@musoke
Copy link
Contributor Author

musoke commented May 9, 2024

I have tested against the since-released Makie v0.20.12 and v0.21.0 and get the output promised above.

Feel free to close this issue if the nans are better handled separately.

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

3 participants