Skip to content

Deprecate frameon kwarg and rcParam to savefig. #11692

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 1 commit into from
Mar 11, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 18, 2018

frameon = False has never worked since its introduction in 2013 (#1875)
due to the buggy implementation that only took it into account if True:

if frameon:
    original_frameon = self.get_frameon()
    self.set_frameon(frameon)

(despite the doc stating otherwise). One can also set the facecolor
kwarg or savefig.facecolor rcParam to fully transparent for the same
effect.

(See also #10023.)

PR Summary

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
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

_deprecated_remain_as_none = {
'axes.hold': ('2.1',),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(other mentions of axes.hold have already been removed)

@anntzer anntzer force-pushed the deprecate-savefig.frameon branch from 8a519c6 to 9d3f5a6 Compare July 18, 2018 13:33
@WeatherGod
Copy link
Member

WeatherGod commented Jul 18, 2018 via email

@anntzer
Copy link
Contributor Author

anntzer commented Jul 18, 2018

But one cannot actually set it to a value of None from the rcfile (https://github.com/matplotlib/matplotlib/blob/v2.2.2/lib/matplotlib/rcsetup.py#L151).

So in practice, the only change removing that entry does is to replace a specific deprecation message ("axes.hold is deprecated, will be removed in 3.0") by a generic unknown-key message ("Bad key "axes.hold"").

@anntzer anntzer force-pushed the deprecate-savefig.frameon branch from 9d3f5a6 to 1b1fbf2 Compare July 18, 2018 14:31
@WeatherGod
Copy link
Member

WeatherGod commented Jul 18, 2018 via email

@anntzer
Copy link
Contributor Author

anntzer commented Jul 18, 2018

But the rc parser will pass the string "None", not the None object. Manually adding such an entry in your rc file confirms that behavior.

@anntzer anntzer force-pushed the deprecate-savefig.frameon branch from 1b1fbf2 to 57269b9 Compare July 18, 2018 14:52
@WeatherGod
Copy link
Member

WeatherGod commented Jul 18, 2018 via email

@anntzer
Copy link
Contributor Author

anntzer commented Jul 18, 2018

One may want to restore the suppression behavior somehow (but that's a separate issue), but right now the only point is to trigger a deprecation message on get and set (and when doing rcParams["blah"] = None directly).
Anyways, you know very well what I think of all this (with python syntax, you could actually pass None in, yada yada); that's not particularly relevant for this PR so let's not derail it.

@ImportanceOfBeingErnest
Copy link
Member

As pointed out in #10939 I would expect there to be a way to get rid of the "frame", i.e. the figure's background patch entirely.
As it stands, one may only turn it transparent. So frameon does have a reason to exist, namely to remove the figure patch from the created figure. (This is relevant for pdf or svg output where depending on frameon a rectangle or no rectangle should be created in the output file.)

@anntzer
Copy link
Contributor Author

anntzer commented Jul 23, 2018

Why does a transparent rectangle in the output file bother you?
Would fig.patch.set_visible(False) work? (Yes, it's an API separate of savefig. But as I argued elsewhere, we shouldn't replicate the entire figure manipulation API in the form of kwargs to savefig.)

@ImportanceOfBeingErnest
Copy link
Member

There are several reasons not wanting a background at all. Let's simply say transparency is unfortunately not handled well in every program you might use your figure with afterwards.

Indeed,

plt.savefig("test.png")
plt.gcf().patch.set_visible(False)
plt.savefig("test.svg")

gives the expected result.

But that is somehow inconsistent. If the figure patch is the object to manipulate for the saved figure's background appearance, one would expect that to be the case in general, not only for set_visible.

I.e. the following does not produce a green background,

plt.gcf().set_facecolor("palegreen")
plt.savefig("test.png")
plt.savefig("test.svg")

@anntzer
Copy link
Contributor Author

anntzer commented Jul 23, 2018

That's because savefig overrides facecolor and that's exactly why I proposed #10023.
Perhaps at least (in #10023) we can kill facecolor and edgecolor, and leave the discussion for transparent (which does not directly map to a single property) for later?

@ImportanceOfBeingErnest
Copy link
Member

Not sure I'm following here, but there sure are reasons to let the saved background be different from the one shown on screen, and to do this within the savefig. (Arguments are given precisely in #10023) The full API is there, it's just not implemented correctly for frameon.

One could of course make that more consistent, in the sense of savefig(..., **kwargs) where **kwargs are passed on to the figure patch of the saved figure. So frameon will become visible and transparent will need to be set via facecolor=(1,1,1,0).

@anntzer
Copy link
Contributor Author

anntzer commented Jul 23, 2018

I'd rather have the API proposed in #10023 (comment). Let's move the discussion there?
Note that transparent also modifies the axes' facecolors.

@anntzer anntzer force-pushed the deprecate-savefig.frameon branch from 57269b9 to b69f8e6 Compare September 25, 2018 04:39
The following API elements are deprecated:

- the ``frameon`` kwarg to ``savefig`` and the ``savefig.frameon`` rcParam (use
``facecolor`` instead),
Copy link
Member

Choose a reason for hiding this comment

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

Can you please be a bit more specific? What values does one have to pass to facecolor to obtain the effect of frameon=True/False.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clarified

@anntzer anntzer force-pushed the deprecate-savefig.frameon branch from b69f8e6 to d8a126c Compare March 3, 2019 20:45
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Anybody can merge after CI pass.

``frameon = False`` has *never* worked since its introduction in 2013
due to the buggy implementation that only took it into account if True:

    if frameon:
        original_frameon = self.get_frameon()
        self.set_frameon(frameon)

(despite the doc stating otherwise).  One can also set the facecolor
kwarg or savefig.facecolor rcParam to fully transparent for the same
effect.
@anntzer anntzer force-pushed the deprecate-savefig.frameon branch from d8a126c to 897c497 Compare March 3, 2019 21:09
jklymak
jklymak previously requested changes Mar 3, 2019
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Blocking on further discussion tomorrow on the call. I think @ImportanceOfBeingErnest has some valid points and we are going to get a lot of blowback about this.

@anntzer
Copy link
Contributor Author

anntzer commented Mar 4, 2019

Let's simply say transparency is unfortunately not handled well in every program you might use your figure with afterwards.

Do you have a specific example in mind?

@jklymak jklymak dismissed their stale review March 11, 2019 20:04

discussed

@tacaswell
Copy link
Member

Going to merge this, but am open to reverting if we get much push back on this after it is released. I think running this through controlling the color / transparency of the patch directly is clearer than an independent flag.

@tacaswell tacaswell merged commit 0499a18 into matplotlib:master Mar 11, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 11, 2019
@anntzer anntzer deleted the deprecate-savefig.frameon branch March 11, 2019 21:00
tacaswell added a commit that referenced this pull request Mar 12, 2019
…692-on-v3.1.x

Backport PR #11692 on branch v3.1.x (Deprecate frameon kwarg and rcParam to savefig.)
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.

6 participants