Skip to content

Add a (skippable) check that the axes have equal aspect ratio. #61

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

Merged
merged 2 commits into from
Jan 5, 2025

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 8, 2024

When the scalebar is not drawn on an aspect where imshow() has been called (e.g., a point cloud made with plot()), the axes aspect ratio is not automatically set to 1, in which case the scale bar will be wrong (or rather, it will only be correct in the direction (horizontal or vertical) in which it is drawn).

To avoid mistakes, add a check for the aspect ratio, emitting a warning when appropriate. The check can be skipped by using new variants for rotation: it can now be set to "horizontal-only" ("the scalebar only applies to the horizontal direction") or "vertical-only". (This could also have been a separate kwarg, but something like check_aspect=False reads a bit awkwardly to me -- let me know if you'd prefer that.)

README.md Outdated
By default, matplotlib_scalebar checks whether the axes have equal aspect ratio
(so that the scale bar applies both for the x and the y directions), and emits
a warning if this is not the case. This warning can be suppressed by setting
*rotation* to `horizontal-only` ("the colorbar only applies to the horizontal
Copy link
Owner

Choose a reason for hiding this comment

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

colorbar? Shouldn't it be "scale bar"?

README.md Outdated
(so that the scale bar applies both for the x and the y directions), and emits
a warning if this is not the case. This warning can be suppressed by setting
*rotation* to `horizontal-only` ("the colorbar only applies to the horizontal
direction") or `vertical-only` ("the colorbar only applies to the vertical
Copy link
Owner

Choose a reason for hiding this comment

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

same here

@@ -33,7 +35,7 @@ def scalebar():

yield scalebar

plt.draw()
Copy link
Owner

Choose a reason for hiding this comment

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

I think the draw is important here to make sure the scale bar is drawn. It doesn't look that it will impact your unit test

Copy link
Owner

@ppinard ppinard left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. I agree having a warning when the aspect ratio is not 1 would be useful, as 99% of the time the scale bar will be used on plots with an aspect ratio of 1.

When the scalebar is not drawn on an aspect where imshow() has been
called (e.g., a point cloud made with plot()), the axes aspect ratio is
not automatically set to 1, in which case the scale bar will be wrong
(or rather, it will only be correct in the direction (horizontal or
vertical) in which it is drawn).

To avoid mistakes, add a check for the aspect ratio, emitting a warning
when appropriate.  The check can be skipped by using new variants for
`rotation`: it can now be set to "horizontal-only" ("the scalebar only
applies to the horizontal direction") or "vertical-only".  (This could
also have been a separate kwarg, but something like `check_aspect=False`
reads a bit awkwardly to me.)
@anntzer
Copy link
Contributor Author

anntzer commented Jan 4, 2025

Thanks, I addressed your comments.

@codecov-commenter
Copy link

codecov-commenter commented Jan 5, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.93%. Comparing base (2c57173) to head (a30887f).
Report is 8 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
- Coverage   91.46%   89.93%   -1.54%     
==========================================
  Files           3        3              
  Lines         422      437      +15     
==========================================
+ Hits          386      393       +7     
- Misses         36       44       +8     

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

@ppinard ppinard merged commit c1a7059 into ppinard:master Jan 5, 2025
3 of 4 checks passed
@anntzer anntzer deleted the rotation-only branch January 5, 2025 15:54
zezhong-zhang pushed a commit to zezhong-zhang/matplotlib-scalebar that referenced this pull request Feb 20, 2025
…rd#61)

* Add a (skippable) check that the axes have equal aspect ratio.

When the scalebar is not drawn on an aspect where imshow() has been
called (e.g., a point cloud made with plot()), the axes aspect ratio is
not automatically set to 1, in which case the scale bar will be wrong
(or rather, it will only be correct in the direction (horizontal or
vertical) in which it is drawn).

To avoid mistakes, add a check for the aspect ratio, emitting a warning
when appropriate.  The check can be skipped by using new variants for
`rotation`: it can now be set to "horizontal-only" ("the scalebar only
applies to the horizontal direction") or "vertical-only".  (This could
also have been a separate kwarg, but something like `check_aspect=False`
reads a bit awkwardly to me.)

* Try to fix CI

---------

Co-authored-by: Philippe Pinard <philippe.pinard@gmail.com>
zezhong-zhang pushed a commit to zezhong-zhang/matplotlib-scalebar that referenced this pull request Feb 20, 2025
…rd#61)

* Add a (skippable) check that the axes have equal aspect ratio.

When the scalebar is not drawn on an aspect where imshow() has been
called (e.g., a point cloud made with plot()), the axes aspect ratio is
not automatically set to 1, in which case the scale bar will be wrong
(or rather, it will only be correct in the direction (horizontal or
vertical) in which it is drawn).

To avoid mistakes, add a check for the aspect ratio, emitting a warning
when appropriate.  The check can be skipped by using new variants for
`rotation`: it can now be set to "horizontal-only" ("the scalebar only
applies to the horizontal direction") or "vertical-only".  (This could
also have been a separate kwarg, but something like `check_aspect=False`
reads a bit awkwardly to me.)

* Try to fix CI

---------

Co-authored-by: Philippe Pinard <philippe.pinard@gmail.com>
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.

3 participants