Skip to content

Add helper for setting axis limits in facetgrid - #7046

Merged
Illviljan merged 6 commits into
pydata:mainfrom
Illviljan:facetgrid_add_lims
Sep 25, 2022
Merged

Add helper for setting axis limits in facetgrid#7046
Illviljan merged 6 commits into
pydata:mainfrom
Illviljan:facetgrid_add_lims

Conversation

@Illviljan

@IllviljanIllviljan commented Sep 16, 2022

Copy link
Copy Markdown
Contributor

This PR adds a helper method that sets the same axis limits for all plots in a facetgrid.
Helpful when

  • wanting specific limits for all plots.
  • you want to make sure all data is visible by simply using the method without any inputs. Which is not certain if sharex/sharey isn't used, relevant when using 3d plots as they don't work.

Split up from #6778.

@mathausemathause left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Small comment but I am also fine to merge as is.

Comment threadxarray/plot/facetgrid.py Outdated
Comment on lines +494 to +502
# Find the plot with the largest xlim values:
for ax in self.axes.flat:
get_lim: None | Callable[[], tuple[float, float]] = getattr(
ax, f"get_{k}lim", None
)
if get_lim:
l0, l1 = get_lim()
l0_old, l1_old = lims_largest[k]
lims_largest[k] = (min(l0, l0_old), max(l1, l1_old))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You could potentially avoid some dict lookups and only assign them at the end - but I don't think it really matters.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Hmm, I'm not seeing what you're seeing. Feel free to push a commit if you like.

Comment threadxarray/plot/facetgrid.py Outdated
Illviljanand others added 2 commits September 23, 2022 21:30
Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com>
@Illviljan

Copy link
Copy Markdown
ContributorAuthor

Thanks @mathause! I'll merge this in a few days.

@IllviljanIllviljan added the plan to merge Final call for comments label Sep 23, 2022
@headtr1ck

Copy link
Copy Markdown
Collaborator

You don't need to specify int | float type, only float works :)

@Illviljan
Illviljan merged commit 968443c into pydata:mainSep 25, 2022

@keewiskeewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

a bit late, but I've got a few comments that might be good to address. The outdated parameter types should definitely be updated but I won't insist on renaming the variables.

Comment threadxarray/plot/facetgrid.py
Comment threadxarray/plot/facetgrid.py
Comment threadxarray/plot/facetgrid.py
@Illviljan

Copy link
Copy Markdown
ContributorAuthor

To be continued in #7082.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plan to mergeFinal call for commentstopic-plotting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Illviljan@headtr1ck@mathause@keewis