Skip to content

fix colorbar region labels position according to region values #86

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zenWai
Copy link
Contributor

@zenWai zenWai commented Mar 29, 2025

Description

What is this PR

  • Bug fix

Why is this PR needed?
Issues with region labeling on colorbar #85

examples with PR change

Example colorbar with the fix heatmap_2d_subplots.py with label_regions=True,

How has this PR been tested?

/examples, other cases and the implemented test_heatmap_2d_colorbar.py

Is this a breaking change?

no

Does this PR require an update to the documentation?

no

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

- Use single method for colorbar creation.
- Show only colorbar labels for regions that are actually visible in the subplot.
- Set colorbar tick values and labels in conformity with self.values and visible regions and (vmin vmax) values.
Copy link

codecov bot commented Mar 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.66%. Comparing base (4e3bf9e) to head (055825a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   70.03%   73.66%   +3.63%     
==========================================
  Files           5        5              
  Lines         327      338      +11     
==========================================
+ Hits          229      249      +20     
+ Misses         98       89       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zenWai
Copy link
Contributor Author

zenWai commented Mar 29, 2025

Current colorbar labeling behaviour with 055825a label_regions=True:

  • Shows region acronyms as tick labels on the colorbar at positions corresponding to their values defined by user.
  • Shows region acronyms of regions that are on the (sliced position / currently present on subplot).
  • Regions that are within the vmin and vmax of the colorbar are labeled.
  • cases where two regions have the same value, only one region acronym is presented on the colorbar(gets redrawn by mpl) at the corresponding value position.

In my opinion, it could be good to take this opportunity to change the current naming of the parameter label_regions to something that represents the relation to the colorbar, hmm...

@zenWai zenWai marked this pull request as ready for review March 29, 2025 21:31
@alessandrofelder alessandrofelder self-requested a review March 31, 2025 14:45
@alessandrofelder
Copy link
Member

Thanks @zenWai - might not get to this until the end of the week/early next week unfortunately

Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this @zenWai

it could be good to take this opportunity to change the current naming of the parameter label_regions to something that represents the relation to the colorbar,

I agree, from my understanding of the codebase. Something like show_colorbar?

In general, I think this looks reasonable (I don't know the heatmap codebase very well! So feel free to push back and help me clarify my thinking). I've pointed out where I think the tests are hard to read IMO - maybe you could split them up a bit more into smaller tests, which would help me also understand your intentions better?

settings.INTERACTIVE = False
settings.OFFSCREEN = True

# mock projected data for get_structures_slice_coords
Copy link
Member

Choose a reason for hiding this comment

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

Could the mock projected data be provided through a fixture?

Comment on lines +97 to +100
Checks that:
- colorbar display is controlled by show_cbar parameter.
- colorbar tick values and labels match visible regions.
- correct calls are made based on parameter combinations.
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to split up into several tests?
The complicated parameters are quite hard to read and understand.

):
heatmap_2d.show(show_cbar=True)

if test_case.get("description") in [
Copy link
Member

Choose a reason for hiding this comment

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

The long if ... elif ... elif ... else suggests to me that we should split this into several unit tests. I think this would also help with code legibility.

@alessandrofelder
Copy link
Member

Hey @zenWai - let us know whether you're planning to respond/address my comments (no rush!) or you'd like the core team to take this on (when they find time)

@alessandrofelder
Copy link
Member

alessandrofelder commented Jun 12, 2025

Hey @zenWai - just another ping to ask whether you'd like to continue on this and #87... if not, that's absolutely fine. It's possible the core developers might be able to wrap it up for you, but not sure when we'll have the time.

Either way - thanks for contributing!

@zenWai
Copy link
Contributor Author

zenWai commented Jun 23, 2025

Thanks for the pings, I will have it ready by this weekend and I will be arround to finish it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants