-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Set figure width and height with set_size_inches #4677
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,29 @@ def _as_mpl_axes(self): | |
plt.close(fig) | ||
|
||
|
||
@cleanup | ||
def test_set_fig_size(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hurray tests! |
||
fig = plt.figure() | ||
|
||
# check figwidth | ||
fig.set_figwidth(5) | ||
assert_equal(fig.get_figwidth(), 5) | ||
|
||
# check figheight | ||
fig.set_figheight(1) | ||
assert_equal(fig.get_figheight(), 1) | ||
|
||
# check using set_size_inches | ||
fig.set_size_inches(2, 4) | ||
assert_equal(fig.get_figwidth(), 2) | ||
assert_equal(fig.get_figheight(), 4) | ||
|
||
# check using tuple to first argument | ||
fig.set_size_inches((1, 3)) | ||
assert_equal(fig.get_figwidth(), 1) | ||
assert_equal(fig.get_figheight(), 3) | ||
|
||
|
||
if __name__ == "__main__": | ||
import nose | ||
nose.runmodule(argv=['-s', '--with-doctest'], exit=False) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the width...
Do we also want to add a comment that we don't recommend this? I remember from reading comments in the backend that we considered this bad practice (so I guess we may remove this at some point?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment here wouldn't help much. None of our code is using the tuple argument form. Ideally, set_width and set_height would not be needed at all; they could be handled in set_size_inches using keywords, with both w and h defaulted to None.
Does anything actually use set_width and/or set_height at all? I imagine that something must use them, or the issue of changing them to go through set_size_inches would not have arisen. Nevertheless, it seems like this is a place where we have the opportunity for some longer-term deprecation and code condensation to reign in our sprawling API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just made it so it would be backwards compatible for how it works currently, but I agree it's kind of strange to support both the tuple and the arguments. I don't know if anything actually uses the tuple notation for this.
I personally use
set_figwidth
andset_figheight
a lot, which is how this came up, but that's also partially because I didn't know aboutset_size_inches
. I like the suggestion of having both width and height be keyword arguments inset_size_inches
and allow setting either or both, and then deprecatingset_figwidth
andset_figheight
. Is there a reason, though, for it beingset_size_inches
rather than justset_size
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_xlim/set_ylim supports this notation, I think.
On Mon, Jul 13, 2015 at 3:55 PM, Jessica B. Hamrick <
notifications@github.com> wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@efiring Yup I agree internal code so not much point here, but what about on the lines above in the function definition? See
FigureManagerTkAgg.resize
for the comment I referred to, should we do something similar here? I have also just done a search for sfw and sfh and only these methods come up.@jhamrick I think
set_size
sounds confusing as it contains no units, it inches, centimetres, pixels, etcetera. I guess we do it by inches because of dpi (dots per square inch), a rather odd unit, but used everywhere in graphics, I have never seen dpcm :(. Perhaps you should also take a look atThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, and it has its good points; but I'm not sure it's worth the added API complexity to support this form everywhere. set_xlim and set_ylim are higher level than set_size_inches, so it is less disruptive to simplify the latter than the former.
As for set_size_inches versus set_size: I suspect that like much in mpl, it is an accident of the way it evolved. Whoever put it in decided to make it very clear what the units are.