##// END OF EJS Templates
Fix local import of select_figure_formats....
Thomas Kluyver -
Show More
@@ -1,117 +1,117
1 1 """Configurable for configuring the IPython inline backend
2 2
3 3 This module does not import anything from matplotlib.
4 4 """
5 5 #-----------------------------------------------------------------------------
6 6 # Copyright (C) 2011 The IPython Development Team
7 7 #
8 8 # Distributed under the terms of the BSD License. The full license is in
9 9 # the file COPYING, distributed as part of this software.
10 10 #-----------------------------------------------------------------------------
11 11
12 12 #-----------------------------------------------------------------------------
13 13 # Imports
14 14 #-----------------------------------------------------------------------------
15 15
16 16 from IPython.config.configurable import SingletonConfigurable
17 17 from IPython.utils.traitlets import (
18 18 Dict, Instance, CaselessStrEnum, Set, Bool, Int, TraitError, Unicode
19 19 )
20 20 from IPython.utils.warn import warn
21 21
22 22 #-----------------------------------------------------------------------------
23 23 # Configurable for inline backend options
24 24 #-----------------------------------------------------------------------------
25 25
26 26 def pil_available():
27 27 """Test if PIL/Pillow is available"""
28 28 out = False
29 29 try:
30 30 from PIL import Image
31 31 out = True
32 32 except:
33 33 pass
34 34 return out
35 35
36 36 # inherit from InlineBackendConfig for deprecation purposes
37 37 class InlineBackendConfig(SingletonConfigurable):
38 38 pass
39 39
40 40 class InlineBackend(InlineBackendConfig):
41 41 """An object to store configuration of the inline backend."""
42 42
43 43 def _config_changed(self, name, old, new):
44 44 # warn on change of renamed config section
45 45 if new.InlineBackendConfig != old.InlineBackendConfig:
46 46 warn("InlineBackendConfig has been renamed to InlineBackend")
47 47 super(InlineBackend, self)._config_changed(name, old, new)
48 48
49 49 # The typical default figure size is too large for inline use,
50 50 # so we shrink the figure size to 6x4, and tweak fonts to
51 51 # make that fit.
52 52 rc = Dict({'figure.figsize': (6.0,4.0),
53 53 # play nicely with white background in the Qt and notebook frontend
54 54 'figure.facecolor': (1,1,1,0),
55 55 'figure.edgecolor': (1,1,1,0),
56 56 # 12pt labels get cutoff on 6x4 logplots, so use 10pt.
57 57 'font.size': 10,
58 58 # 72 dpi matches SVG/qtconsole
59 59 # this only affects PNG export, as SVG has no dpi setting
60 60 'savefig.dpi': 72,
61 61 # 10pt still needs a little more room on the xlabel:
62 62 'figure.subplot.bottom' : .125
63 63 }, config=True,
64 64 help="""Subset of matplotlib rcParams that should be different for the
65 65 inline backend."""
66 66 )
67 67
68 68 figure_formats = Set({'png'}, config=True,
69 69 help="""A set of figure formats to enable: 'png',
70 70 'retina', 'jpeg', 'svg', 'pdf'.""")
71 71
72 72 def _update_figure_formatters(self):
73 73 if self.shell is not None:
74 from IPython.core.pylabtools import select_figure_formats
74 75 select_figure_formats(self.shell, self.figure_formats, **self.print_figure_kwargs)
75 76
76 77 def _figure_formats_changed(self, name, old, new):
77 from IPython.core.pylabtools import select_figure_formats
78 78 if 'jpg' in new or 'jpeg' in new:
79 79 if not pil_available():
80 80 raise TraitError("Requires PIL/Pillow for JPG figures")
81 81 self._update_figure_formatters()
82 82
83 83 figure_format = Unicode(config=True, help="""The figure format to enable (deprecated
84 84 use `figure_formats` instead)""")
85 85
86 86 def _figure_format_changed(self, name, old, new):
87 87 if new:
88 88 self.figure_formats = {new}
89 89
90 90 print_figure_kwargs = Dict({'bbox_inches' : 'tight'}, config=True,
91 91 help="""Extra kwargs to be passed to fig.canvas.print_figure.
92 92
93 93 Logical examples include: bbox_inches, quality (for jpeg figures), etc.
94 94 """
95 95 )
96 96 _print_figure_kwargs_changed = _update_figure_formatters
97 97
98 98 close_figures = Bool(True, config=True,
99 99 help="""Close all figures at the end of each cell.
100 100
101 101 When True, ensures that each cell starts with no active figures, but it
102 102 also means that one must keep track of references in order to edit or
103 103 redraw figures in subsequent cells. This mode is ideal for the notebook,
104 104 where residual plots from other cells might be surprising.
105 105
106 106 When False, one must call figure() to create new figures. This means
107 107 that gcf() and getfigs() can reference figures created in other cells,
108 108 and the active figure can continue to be edited with pylab/pyplot
109 109 methods that reference the current active figure. This mode facilitates
110 110 iterative editing of figures, and behaves most consistently with
111 111 other matplotlib backends, but figure barriers between cells must
112 112 be explicit.
113 113 """)
114 114
115 115 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
116 116
117 117
General Comments 0
You need to be logged in to leave comments. Login now