##// END OF EJS Templates
Refining the matplotlib APIs in IPython.display.
Brian E. Granger -
Show More
@@ -24,7 +24,7 b' import struct'
24 24
25 25 from IPython.utils.py3compat import (string_types, cast_bytes_py2, cast_unicode,
26 26 unicode_type)
27
27 from IPython.testing.skipdoctest import skip_doctest
28 28 from .displaypub import publish_display_data
29 29
30 30 #-----------------------------------------------------------------------------
@@ -719,18 +719,53 b' def clear_output(wait=False):'
719 719 io.stderr.flush()
720 720
721 721
722 def select_matplotlib_formats(formats, quality=90):
723 """Select figure formats for the inline backend.
722 @skip_doctest
723 def set_matplotlib_formats(*formats, **kwargs):
724 """Select figure formats for the inline backend. Optionally pass quality for JPEG.
725
726 For example, this enables PNG and JPEG output with a JPEG quality of 90%::
727
728 In [1]: set_matplotlib_formats('png', 'jpeg', quality=90)
729
730 To set this in your config files use the following::
731
732 c.InlineBackend.figure_formats = {'pdf', 'png', 'svg'}
724 733
725 734 Parameters
726 ==========
727 formats : list
735 ----------
736 *formats : list, tuple
728 737 One or a set of figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
729 738 quality : int
730 A percentage for the quality of JPEG figures.
739 A percentage for the quality of JPEG figures. Defaults to 90.
731 740 """
732 741 from IPython.core.interactiveshell import InteractiveShell
733 742 from IPython.core.pylabtools import select_figure_formats
734 743 shell = InteractiveShell.instance()
735 744 select_figure_formats(shell, formats, quality=90)
736 745
746 @skip_doctest
747 def set_matplotlib_close(close):
748 """Should the inline backend close all figures automatically.
749
750 By default, the inline backend used in the IPython Notebook will close all
751 matplotlib figures automatically after each cell is run. This means that
752 plots in different cells won't interfere. Sometimes, you may want to make
753 a plot in one cell and then refine it in later cells. This can be accomplished
754 by::
755
756 In [1]: set_matplotlib_close(False)
757
758 To set this in your config files use the following::
759
760 c.InlineBackend.close_figures = False
761
762 Parameters
763 ----------
764 close : bool
765 Should all matplotlib figures be automatically closed after each cell is
766 run?
767 """
768 from IPython.kernel.zmq.pylab.backend_inline import InlineBackend
769 ilbe = InlineBackend.instance()
770 ilbe.close_figures = close
771
@@ -47,28 +47,32 b' class PylabMagics(Magics):'
47 47 """Set up matplotlib to work interactively.
48 48
49 49 This function lets you activate matplotlib interactive support
50 at any point during an IPython session.
51 It does not import anything into the interactive namespace.
50 at any point during an IPython session. It does not import anything
51 into the interactive namespace.
52 52
53 If you are using the inline matplotlib backend for embedded figures,
54 you can adjust its behavior via the %config magic::
53 If you are using the inline matplotlib backend in the IPython Notebook
54 you can set which figure formats are enabled using the following::
55 55
56 # enable SVG figures, necessary for SVG+XHTML export in the qtconsole
57 In [1]: %config InlineBackend.figure_format = 'svg'
56 In [1]: from IPython.display import set_matplotlib_formats
58 57
59 # change the behavior of closing all figures at the end of each
60 # execution (cell), or allowing reuse of active figures across
61 # cells:
62 In [2]: %config InlineBackend.close_figures = False
58 In [2]: set_matplotlib_formats('pdf', 'svg')
59
60 See the docstring of `IPython.display.set_matplotlib_formats` and
61 `IPython.display.set_matplotlib_close` for more information on
62 changing the behavior of the inline backend.
63 63
64 64 Examples
65 65 --------
66 In this case, where the MPL default is TkAgg::
66 To enable the inline backend for usage with the IPython Notebook::
67
68 In [1]: %matplotlib inline
69
70 In this case, where the matplotlib default is TkAgg::
67 71
68 72 In [2]: %matplotlib
69 73 Using matplotlib backend: TkAgg
70 74
71 But you can explicitly request a different backend::
75 But you can explicitly request a different GUI backend::
72 76
73 77 In [3]: %matplotlib qt
74 78 """
General Comments 0
You need to be logged in to leave comments. Login now