Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: add fill argument to AnchoredSizeBar #8829

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

Closed

Conversation

magnunor
Copy link
Contributor

PR Summary

This pull request introduces a optional AnchoredSizeBar argument for filling the rectangle used in the sizebar.

Having the option to have a filled rectangle is useful when plotting scalebars for microscopy images, where this is the conventional way.

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

fig, ax = plt.subplots(figsize=(3, 3))

bar0 = AnchoredSizeBar(ax.transData, 0.3, '0.3', loc=3, frameon=False, size_vertical=0.05)
ax.add_artist(bar0)
bar1 = AnchoredSizeBar(ax.transData, 0.3, '0.3', loc=4, frameon=False, fill=True, size_vertical=0.05)
ax.add_artist(bar1)
fig.savefig("sizebar_fill.png")

sizebar_fill

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

@@ -232,7 +232,7 @@ class AnchoredSizeBar(AnchoredOffsetbox):
def __init__(self, transform, size, label, loc,
pad=0.1, borderpad=0.1, sep=2,
frameon=True, size_vertical=0, color='black',
label_top=False, fontproperties=None,
fill=False, label_top=False, fontproperties=None,
Copy link
Member

Choose a reason for hiding this comment

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

please put this last to not break the API. Technically someone could be passing in 12 positional arguments.

@tacaswell
Copy link
Member

In general 👍 but needs a few tweaks.

@magnunor
Copy link
Contributor Author

Fixed!

I wasn't completely sure how to format the whats_new, since there were some variations in the already existing files in that folder.

@tacaswell
Copy link
Member

This was last changed in e5b5425 to fix #5757 . This change should not affect that (as the default does not change). It looks like what is going on is:

It would not be unreasonable to change the default value of fill based on if the height is >0

if fill is None:
    fill = size_vertical > 0

Bit trickier to document, but probably more user-friendly in the long run.

If we were to do this again, I would say that the default height should be 0.01 or something like that, but 🤷‍♂️ .

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jun 30, 2017
@tacaswell tacaswell dismissed their stale review July 1, 2017 18:55

Original concerns addressed, but should be some discussion over making default depend on size_vertical

@magnunor magnunor closed this Jul 7, 2017
@magnunor
Copy link
Contributor Author

magnunor commented Jul 7, 2017

Functionality being implemented in #8835

@magnunor magnunor deleted the ENH_anchored_size_bar_fill branch May 1, 2018 06:48
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