Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: rect for constrained_layout#22627

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
oscargus merged 1 commit intomatplotlib:mainfromjklymak:enh-rect-for-CL
May 8, 2022

Conversation

jklymak
Copy link
Member

PR Summary

Closes#22623 adding a rectangle to constrained layout

import matplotlib.pyplot as pltimport numpy as npimport matplotlib as mplfig, ax = plt.subplots(layout='constrained')fig.get_layout_engine().set(rect=[0.1, 0.1, 0.5, 0.5])plt.show()

TestCLRect

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

tillahoffmann reacted with thumbs up emoji
@jklymakjklymak added the topic: geometry managerLayoutEngine, Constrained layout, Tight layout labelMar 9, 2022
@jklymakjklymak added this to thev3.6.0 milestoneMar 9, 2022
Copy link
Contributor

@greglucasgreglucas left a comment

Choose a reason for hiding this comment

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

Looks good.

@@ -87,14 +87,18 @@ def do_constrained_layout(fig, h_pad, w_pad,
of 0.1 of the figure width between each column.
If h/wspace < h/w_pad, then the pads are used instead.

rect : [l, b, w, h]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor suggestion for the inputs here.

Suggested change
rect :[l,b,w,h]
rect :tupleof4floats

This should be the type, you're already specifying what they are below.

Also, do you want to change all the default inputs to tuples instead of a list,rect=(0, 0, 1, 1) to avoid mutability concerns?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm fine to do this, but note that we don't do this elsewhere in the library when we specify rectangles?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, it seems rects are specified in a lot of different ways!

rect : tuple[float, float, float, float], optionalrect : sequence of floatrect : tuple (left, bottom, right, top), default: (0, 0, 1, 1)rect : tuple of 4 floats, default: (0, 0, 1, 1)rect : [left, bottom, width, height]rect : (float, float, float, float)

I'm pretty indifferent on most of those styles, but I don't think the orientation belongs on this first line. My approval still stands regardless of which format of documentation you choose, consolidation ofrect across matplotlib should be a follow-up issue.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I changed this, though this is a private module.

hc = [self.lefts[0] == 0,
self.rights[-1] == 1,
if not isinstance(parent, LayoutGrid):
# specify a rectangle in figure co-ordinates
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# specify a rectangle in figureco-ordinates
# specify a rectangle in figurecoordinates

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed, though its a private module, and I like the British spelling better (at least I don't add an umlaut!) ;-)

greglucas reacted with laugh emoji
@jklymakjklymakforce-pushed theenh-rect-for-CL branch 3 times, most recently fromc39027a toacae2c4CompareMarch 11, 2022 05:12
@@ -133,7 +137,7 @@ def do_constrained_layout(fig, h_pad, w_pad,
return layoutgrids


def make_layoutgrids(fig, layoutgrids):
def make_layoutgrids(fig, layoutgrids, rect=[0, 0, 1, 1]):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
defmake_layoutgrids(fig,layoutgrids,rect=[0,0,1,1]):
defmake_layoutgrids(fig,layoutgrids,rect=(0,0,1,1)):

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I guess the immutability is important enough to guard here...

@@ -196,15 +197,20 @@ def __init__(self, *, h_pad=None, w_pad=None,
If h/wspace < h/w_pad, then the pads are used instead.
Default to :rc:`figure.constrained_layout.hspace` and
:rc:`figure.constrained_layout.wspace`.
rect : tuple of 4 floats
Rectangle in figure coordinates to perform constrained layout in
[left, bottom, width, height], each from 0-1.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[left,bottom,width,height],eachfrom0-1.
(left,bottom,width,height),eachfrom0-1.

jklymak reacted with thumbs up emoji
@@ -87,14 +87,18 @@ def do_constrained_layout(fig, h_pad, w_pad,
of 0.1 of the figure width between each column.
If h/wspace < h/w_pad, then the pads are used instead.

rect : tuple of 4 floats
Rectangle in figure coordinates to perform constrained layout in
[left, bottom, width, height], each from 0-1.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[left,bottom,width,height],eachfrom0-1.
(left,bottom,width,height),eachfrom0-1.

Copy link
Member

Choose a reason for hiding this comment

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

Should one possibly add default values here? (And in other locations.)

jklymak reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Btw, doesn't look like there is a renderer parameter (anymore?).

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yes, needed to rebase.

Comment on lines 252 to 254
rect : [l, b, w, h]
Rectangle in figure coordinates to perform constrained layout in
[left, bottom, width, height], each from 0-1.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rect :[l,b,w,h]
Rectangleinfigurecoordinatestoperformconstrainedlayoutin
[left,bottom,width,height],eachfrom0-1.
rect :tupleof4floats
Rectangleinfigurecoordinatestoperformconstrainedlayoutin
(left,bottom,width,height),eachfrom0-1.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fixed all these, also inTightLayoutEngine..

@oscargusoscargus merged commit9537906 intomatplotlib:mainMay 8, 2022
@anntzer
Copy link
Contributor

@jklymak Is there any reason why you deleted pytest.ini and tests.py here?

@jklymak
Copy link
MemberAuthor

No, must have been a rebase gone awry? Sorry I didn't notice that.

@anntzer
Copy link
Contributor

No worries, I'll restore them.

@jklymak
Copy link
MemberAuthor

Looks like we have a new pytest.ini.

@jklymak
Copy link
MemberAuthor

What does test.py do?

@jklymakjklymak deleted the enh-rect-for-CL branchMay 27, 2022 10:07
@anntzer
Copy link
Contributor

It's been discussed a couple of times, e.g. at#20586. I think we should probably get rid of it at some point, but there still seems to be some users for now so that should be discussed separately.

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

@greglucasgreglucasgreglucas approved these changes

@oscargusoscargusoscargus approved these changes

Assignees
No one assigned
Labels
topic: geometry managerLayoutEngine, Constrained layout, Tight layout
Projects
None yet
Milestone
v3.6.0
Development

Successfully merging this pull request may close these issues.

[ENH]: support rect with constrained_layout ("layout only to part of the figure")
4 participants
@jklymak@anntzer@oscargus@greglucas

[8]ページ先頭

©2009-2025 Movatter.jp