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 misaligned colors in colorbar? #4618

Merged
merged 6 commits into from
Nov 29, 2024
Merged

Conversation

briochemc
Copy link
Contributor

@briochemc briochemc commented Nov 22, 2024

Description

Fixes #4121?

Currently the Colorbar built from a contourf may have misaligned colors. For a MWE see #4121 or

l = [1, 2, 5, 10, 20, 50]
x = 0:0.1:51
y = 0:0.1:51
z = [y for x in x, y in y]
fig, ax, plt = contourf(x, y, z; levels = l, extendhigh=:auto, extendlow=:auto)
cb = Colorbar(fig[1, 2], plt; tellheight = false)

which produces this misalignment (I edited the image in Preview to show the differences in colors):

test

The issue seems to be that the continuous_pixels (used to draw the heatmap for the colorbar) are not scaled properly. Simply adding the colorrange kwarg to that call fixes this issue for me, with properly matching colors:

Screenshot 2024-11-22 at 1 27 43 pm

However, I'm not if this breaks other things elsewhere, so hopefully someone can hold my hand to finish this PR?

Type of change

Delete options that do not apply:

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Added an entry in CHANGELOG.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@ffreyer
Copy link
Collaborator

ffreyer commented Nov 25, 2024

Seems fine to me. The plot colormapping code should always consider colorrange so I don't see why Colorbar shouldn't. With the ColorMapping type being constructed, the colorrange should also always be in a standard form.

I would say this can be merged after adding a release note to https://github.com/MakieOrg/Makie.jl/blob/master/CHANGELOG.md and adding a reference image test probably in https://github.com/MakieOrg/Makie.jl/blob/master/ReferenceTests/src/tests/figures_and_makielayout.jl.

@briochemc
Copy link
Contributor Author

I think I did what you asked:

  • Add changelog item
  • Add reference test

I also "fixed" formatting (spacing around kwarg = sign) and added the colorrange kwarg to the heatmap call in the continuous case, assuming it should be there as well.

Please let me know if I missed something!

@briochemc
Copy link
Contributor Author

BTW the reference test is a slightly simplified version of the MWE (removed the colorbar extensions):

master PR
Screenshot 2024-11-26 at 11 19 21 am Screenshot 2024-11-26 at 11 19 31 am

@briochemc
Copy link
Contributor Author

I'm not sure how/where to upload the reference image for the added reference test. Could you help with that?

@ffreyer
Copy link
Collaborator

ffreyer commented Nov 26, 2024

I'm not sure how/where to upload the reference image for the added reference test. Could you help with that?

That's something Simon, Julius or I need to do.

@briochemc
Copy link
Contributor Author

Is there anything else I need to do?

@ffreyer
Copy link
Collaborator

ffreyer commented Nov 29, 2024

To things changed in Colorbar for recipes:

old new
reference_GLMakie_Colorbar for recipes recorded_GLMakie_Colorbar for recipes

On the center right, the Colorbar now has (slightly) different colors in the -0.5..-0.25 and -0.25..0.5 regions. These now match the colors in the plot exactly, so that's an improvement.

On the center left, the very wide Colorbar got stretched slightly in y direction. It comes from a 3D contour() plot, which lowers to a volume plot. I'm not sure how exactly the colors work here - but it seems like it's all handled early, i.e. in Makie through the ColorMapping object. Colorbar should be reading that more accurately now, so this should be an improvement?

Either way, I updated refimages. If the volume Colorbar is slightly off now it doesn't need to be fixed here.

@ffreyer ffreyer merged commit a4e4d73 into MakieOrg:master Nov 29, 2024
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

Some of the levels are missing from Colorbar
2 participants