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 CairoMakie heatmap cell sizes #3625

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

maxfreu
Copy link

@maxfreu maxfreu commented Feb 12, 2024

Description

Fixes #3619

CairoMakie heatmap cells are currently enlarged by a constant factor of 0.5. This PR changes this to a value relative to the pixel size.

Before:
image

After:
image

There are still some remaining inaccuracies, but its way better than before. This is really important for drawing halfway accurate maps.

Type of change

Delete options that do not apply:

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

Checklist

  • Added an entry in NEWS.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.

@maxfreu
Copy link
Author

maxfreu commented Feb 12, 2024

The heatmap_interpolation.png reference image differs slightly, that's probably why the test failed. If you tell me where to find the code generating the reference output, I can try to fix it. Looks like the pixels within this reference image have variable size; I expected all to be the same, but it's easy to adapt the margin on a per-pixel basis.

@maxfreu
Copy link
Author

maxfreu commented Feb 12, 2024

Margins are now calculated per individual pixel, which should get rid of the difference in the test image.

@maxfreu maxfreu marked this pull request as draft February 12, 2024 16:28
@maxfreu maxfreu marked this pull request as ready for review February 13, 2024 11:45
@maxfreu
Copy link
Author

maxfreu commented Feb 13, 2024

Ok, I think it's not so easy to get this perfectly right, as padding the pixels is already a bit hacky. As the heatmaps only look wrong if NaN is present, I now check for it and:

  1. If no NaN is present, everything should stay as it was.
  2. If NaN is present, the pixel margins are reduced to 5% the pixel width. This introduces aliasing in some cases, but doesn't oversize the pixels completely.

@maxfreu maxfreu marked this pull request as draft February 13, 2024 13:14
@t-bltg t-bltg added the CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo. label Feb 15, 2024
# Rectangles and polygons that are directly adjacent usually show
# white lines between them due to anti aliasing. To avoid this we
# increase their size slightly.


if alpha(colors[i, j]) == 1 && margin_factor > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if using a transparent colormap here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem mostly goes away, but when you set alpha=0.99 for example, there are still some cases where artifacts occur. For example thin lines that shouldn't be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CairoMakie This relates to CairoMakie, the vector backend for Makie based on Cairo.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CairoMakie heatmap pixels overlap
3 participants