Skip to content
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

Added savefig.bbox option to matplotlibrc #1004

Merged
merged 6 commits into from Jul 23, 2012

Conversation

oxling
Copy link
Contributor

@oxling oxling commented Jul 10, 2012

This is from wishlist issue #988. It allows the user to default the bounding box to 'tight.'

Allows the user to set the bounding box to 'tight,' which will override the defaults when saving from the interface.
s = s.lower()
if s in ('tight'):
return s
if s in ('auto'):
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this line does as you intended:

>>> 'a' in ('hello world')
False
>>> 'hello' in ('hello world')
True
>>> 'w' in ('hello world')
True

Adding a trailing comma to turn the thing into a tuple was probably your intention:

>>> 'w' in ('hello world', )
False
>>> 'hello world' in ('hello world', )
True

Copy link
Member

Choose a reason for hiding this comment

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

But really, you may as well just use string equality:

if s == 'auto'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the correction, I'll use string equality.

@WeatherGod
Copy link
Member

The current behavior for the savefig function is to save the visible canvas area if "bbox_inches" was not given or was None. This does not change with the new code. However, there is a slight symantical collision here, as it is a general rule that passing None for a kwarg value means "perform the default behavior", which, in turn, typically means, use the rc default. So, if I set "bbox_inches" to "tight", and pass bbox_inches=None to the savefig kwargs, I get a different result than intended. (Note, this is not a new problem. It has been a growing issue with kwarg handling that really needs to be addressed throughout matplotlib).

I also don't like "auto", because there is nothing automatic about it. In other words, when no bbox is specified, it just uses the existing bbox of the figure. Of course this is a minor quible, and I am probably being too pedantic.

Next, having "auto" as a possible value for bbox_inches implies that one could use "auto" for input to savefig(). This might actually be a good thing in that it might help address my first point.

Finally, there are other kwargs that get activated when bbox_inches is "tight". Adding "pad_inches" should be trivial, but I don't see how we could implement bbox_extra_artists. I guess we would just have to do without bbox_extra_artists, but pad_inches should definitely be included.

@oxling
Copy link
Contributor Author

oxling commented Jul 13, 2012

@WeatherGod OK, I made most of your suggested changes. I changed 'auto' to 'default,' added savefig.pad_inches, and changed the behavior so that passing 'None' will use the value set in the defaults.

@@ -2012,6 +2014,9 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
self.figure.set_edgecolor(edgecolor)

bbox_inches = kwargs.pop("bbox_inches", None)
if bbox_inches == None:
Copy link
Member

Choose a reason for hiding this comment

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

Don't use '==' when testing for None. Always use "is" and "is not".

@WeatherGod
Copy link
Member

I dislike "default" even more than "auto" because which default does it refer to? How about "standard", "keep" or maybe "unchanged"?

@oxling
Copy link
Contributor Author

oxling commented Jul 13, 2012

How about just passing in None instead? That's what the savefig() function expects anyways, and it seems to keep with the same style of passing True or False in the defaults file.

@WeatherGod
Copy link
Member

I would rather avoid clouding the distinction between "None" and None. We already have enough problems as is with that. We already do have None's in the rc file, but those mean the string "None" which is entirely different from the python None. In the rc file, we can not distinguish between the two since everything comes in as strings.

@oxling
Copy link
Contributor Author

oxling commented Jul 13, 2012

OK. Changed to 'standard.'

@WeatherGod
Copy link
Member

ok, remind me if there were anything left holding up this PR? I think all my qualms have been addressed.

@oxling
Copy link
Contributor Author

oxling commented Jul 18, 2012

I don't think there was.

On Jul 18, 2012, at 12:58 AM, Benjamin Rootreply@reply.github.com wrote:

ok, remind me if there were anything left holding up this PR? I think all my qualms have been addressed.


Reply to this email directly or view it on GitHub:
#1004 (comment)

@WeatherGod
Copy link
Member

Oh, right, can you please add a note to docs/users/whats_new.rst?

@WeatherGod
Copy link
Member

Be sure to ping me when you make that last change so I can go ahead and merge this in. Thanks for your work!

@oxling
Copy link
Contributor Author

oxling commented Jul 23, 2012

OK, done. Let me me know if I didn't get the formatting in that file right.

@WeatherGod
Copy link
Member

Ok, looks good to me. Merging it in now. Thanks!

WeatherGod added a commit that referenced this pull request Jul 23, 2012
Added savefig.bbox option to matplotlibrc
@WeatherGod WeatherGod merged commit 561d0da into matplotlib:master Jul 23, 2012
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.

None yet

3 participants