8000 Transparent rcparams by tacaswell · Pull Request #2390 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Transparent rcparams #2390

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 4 commits into from
Sep 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ original location:
thus `colorbar.ColorbarBase.outline` is now a
`matplotlib.patches.Polygon` object.

* The rcParams `savefig.transparent` has been added to control
default transparency when saving figures.
Copy link
Member

Choose a reason for hiding this comment

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

Since this is actually a new feature, it should probably be added to whats_new.rst as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.


.. _changes_in_1_3:


Expand Down
9 changes: 9 additions & 0 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ and :func:`matplotlib.dates.datestr2num`. Support is also added to the unit
conversion interfaces :class:`matplotlib.dates.DateConverter` and
:class:`matplotlib.units.Registry`.

Configuration (rcParams)
------------------------

``savefig.transparent`` added
`````````````````````````````
Controls whether figures are saved with a transparent
background by default. Previously `savefig` always defaulted
to a non-transparent background.

.. _whats-new-1-3:

new in matplotlib-1.3
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ def savefig(self, *args, **kwargs):

kwargs.setdefault('dpi', rcParams['savefig.dpi'])
frameon = kwargs.pop('frameon', rcParams['savefig.frameon'])
transparent = kwargs.pop('transparent', False)
transparent = kwargs.pop('transparent', rcParams['savefig.transparent'])

if transparent:
kwargs.setdefault('facecolor', 'none')
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ def draw():
@docstring.copy_dedent(Figure.savefig)
def savefig(*args, **kwargs):
fig = gcf()
return fig.savefig(*args, **kwargs)
res = fig.savefig(*args, **kwargs)
draw() # need this if 'transparent=True' to reset colors
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand why this is needed. Forgetting the rcParam, what's the difference if I just pass tansparent=True to savefig manually?

Copy link
Member Author

Choose a reason for hiding this comment

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

This change is only tangentally related to the rcParams work.

I noticed while testing with transparent=True in an interactive backend (qt4) that after the save the background patch was still invisible. The savefig code does restore the correct colors, but the display never got updated.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not that comfortable with this change. A quicker alternative might be to capture a frame buffer and fire it back at the canvas. @mdboom do you have any insight?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it be better to use draw_if_interactive? Which now that I think a bit more about it is what I should have done to begin with.

return res


@docstring.copy_dedent(Figure.ginput)
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ def __call__(self, s):
'savefig.pad_inches': [0.1, validate_float],
# default directory in savefig dialog box
'savefig.directory': ['~', six.text_type],
'savefig.transparent': [False, validate_bool],

# Maintain shell focus for TkAgg
'tk.window_focus': [False, validate_bool],
Expand Down
2 changes: 2 additions & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ backend : %(backend)s
#savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter.
#savefig.directory : ~ # default directory in savefig dialog box,
# leave empty to always use current working directory
#savefig.transparent : False # setting that controls whether figures are saved with a
# transparent background by default

# tk backend params
#tk.window_focus : False # Maintain shell focus for TkAgg
Expand Down
0