Skip to content
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
17 changes: 15 additions & 2 deletions matplotlib_inline/backend_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,32 @@ def set_matplotlib_formats(*formats, **kwargs):

For example, this enables PNG and JPEG output with a JPEG quality of 90%::

In [1]: set_matplotlib_formats('png', 'jpeg', quality=90)
In [1]: set_matplotlib_formats('png', 'jpeg',
pil_kwargs={'quality': 90})

To set this in your notebook by `%config` magic::

In [1]: %config InlineBackend.figure_formats = {'png', 'jpeg'}
%config InlineBackend.print_figure_kwargs = \\
{'pil_kwargs': {'quality' : 90}}

To set this in your config files use the following::

c.InlineBackend.figure_formats = {'png', 'jpeg'}
c.InlineBackend.print_figure_kwargs.update({'quality' : 90})
c.InlineBackend.print_figure_kwargs.update({
'pil_kwargs': {'quality' : 90}
})

Parameters
----------
*formats : strs
One or more figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
**kwargs
Keyword args will be relayed to ``figure.canvas.print_figure``.

In addition, see the docstrings of `plt.savefig()`,
`matplotlib.figure.Figure.savefig()`, `PIL.Image.Image.save()` and
:ref:`Pillow Image file formats <handbook/image-file-formats>`.
"""
# build kwargs, starting with InlineBackend config
cfg = InlineBackend.instance()
Expand Down
3 changes: 2 additions & 1 deletion matplotlib_inline/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def _figure_format_changed(self, name, old, new):
{"bbox_inches": "tight"},
help="""Extra kwargs to be passed to fig.canvas.print_figure.
Logical examples include: bbox_inches, quality (for jpeg figures), etc.
Logical examples include: bbox_inches, pil_kwargs, etc. In addition,
see the docstrings of `set_matplotlib_formats`.
""",
).tag(config=True)
_print_figure_kwargs_changed = _update_figure_formatters
Expand Down
Loading