Show More
@@ -0,0 +1,85 b'' | |||
|
1 | """Configurable for configuring the IPython inline backend | |
|
2 | ||
|
3 | This module does not import anything from matplotlib. | |
|
4 | """ | |
|
5 | #----------------------------------------------------------------------------- | |
|
6 | # Copyright (C) 2011 The IPython Development Team | |
|
7 | # | |
|
8 | # Distributed under the terms of the BSD License. The full license is in | |
|
9 | # the file COPYING, distributed as part of this software. | |
|
10 | #----------------------------------------------------------------------------- | |
|
11 | ||
|
12 | #----------------------------------------------------------------------------- | |
|
13 | # Imports | |
|
14 | #----------------------------------------------------------------------------- | |
|
15 | ||
|
16 | from IPython.config.configurable import SingletonConfigurable | |
|
17 | from IPython.utils.traitlets import Dict, Instance, CaselessStrEnum, Bool | |
|
18 | from IPython.utils.warn import warn | |
|
19 | ||
|
20 | #----------------------------------------------------------------------------- | |
|
21 | # Configurable for inline backend options | |
|
22 | #----------------------------------------------------------------------------- | |
|
23 | ||
|
24 | # inherit from InlineBackendConfig for deprecation purposes | |
|
25 | class InlineBackendConfig(SingletonConfigurable): | |
|
26 | pass | |
|
27 | ||
|
28 | class InlineBackend(InlineBackendConfig): | |
|
29 | """An object to store configuration of the inline backend.""" | |
|
30 | ||
|
31 | def _config_changed(self, name, old, new): | |
|
32 | # warn on change of renamed config section | |
|
33 | if new.InlineBackendConfig != old.InlineBackendConfig: | |
|
34 | warn("InlineBackendConfig has been renamed to InlineBackend") | |
|
35 | super(InlineBackend, self)._config_changed(name, old, new) | |
|
36 | ||
|
37 | # The typical default figure size is too large for inline use, | |
|
38 | # so we shrink the figure size to 6x4, and tweak fonts to | |
|
39 | # make that fit. | |
|
40 | rc = Dict({'figure.figsize': (6.0,4.0), | |
|
41 | # play nicely with white background in the Qt and notebook frontend | |
|
42 | 'figure.facecolor': 'white', | |
|
43 | 'figure.edgecolor': 'white', | |
|
44 | # 12pt labels get cutoff on 6x4 logplots, so use 10pt. | |
|
45 | 'font.size': 10, | |
|
46 | # 72 dpi matches SVG/qtconsole | |
|
47 | # this only affects PNG export, as SVG has no dpi setting | |
|
48 | 'savefig.dpi': 72, | |
|
49 | # 10pt still needs a little more room on the xlabel: | |
|
50 | 'figure.subplot.bottom' : .125 | |
|
51 | }, config=True, | |
|
52 | help="""Subset of matplotlib rcParams that should be different for the | |
|
53 | inline backend.""" | |
|
54 | ) | |
|
55 | ||
|
56 | figure_format = CaselessStrEnum(['svg', 'png', 'retina'], default_value='png', config=True, | |
|
57 | help="The image format for figures with the inline backend.") | |
|
58 | ||
|
59 | def _figure_format_changed(self, name, old, new): | |
|
60 | from IPython.core.pylabtools import select_figure_format | |
|
61 | if self.shell is None: | |
|
62 | return | |
|
63 | else: | |
|
64 | select_figure_format(self.shell, new) | |
|
65 | ||
|
66 | close_figures = Bool(True, config=True, | |
|
67 | help="""Close all figures at the end of each cell. | |
|
68 | ||
|
69 | When True, ensures that each cell starts with no active figures, but it | |
|
70 | also means that one must keep track of references in order to edit or | |
|
71 | redraw figures in subsequent cells. This mode is ideal for the notebook, | |
|
72 | where residual plots from other cells might be surprising. | |
|
73 | ||
|
74 | When False, one must call figure() to create new figures. This means | |
|
75 | that gcf() and getfigs() can reference figures created in other cells, | |
|
76 | and the active figure can continue to be edited with pylab/pyplot | |
|
77 | methods that reference the current active figure. This mode facilitates | |
|
78 | iterative editing of figures, and behaves most consistently with | |
|
79 | other matplotlib backends, but figure barriers between cells must | |
|
80 | be explicit. | |
|
81 | """) | |
|
82 | ||
|
83 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
|
84 | ||
|
85 |
@@ -45,6 +45,7 b' from IPython.kernel.zmq.kernelapp import (' | |||
|
45 | 45 | kernel_aliases, |
|
46 | 46 | IPKernelApp |
|
47 | 47 | ) |
|
48 | from IPython.kernel.zmq.pylab.config import InlineBackend | |
|
48 | 49 | from IPython.kernel.zmq.session import Session, default_secure |
|
49 | 50 | from IPython.kernel.zmq.zmqshell import ZMQInteractiveShell |
|
50 | 51 | from IPython.kernel.connect import ConnectionFileMixin |
@@ -110,14 +111,7 b' aliases.update(app_aliases)' | |||
|
110 | 111 | # IPythonConsole |
|
111 | 112 | #----------------------------------------------------------------------------- |
|
112 | 113 | |
|
113 | classes = [IPKernelApp, ZMQInteractiveShell, KernelManager, ProfileDir, Session] | |
|
114 | ||
|
115 | try: | |
|
116 | from IPython.kernel.zmq.pylab.backend_inline import InlineBackend | |
|
117 | except ImportError: | |
|
118 | pass | |
|
119 | else: | |
|
120 | classes.append(InlineBackend) | |
|
114 | classes = [IPKernelApp, ZMQInteractiveShell, KernelManager, ProfileDir, Session, InlineBackend] | |
|
121 | 115 | |
|
122 | 116 | class IPythonConsoleApp(ConnectionFileMixin): |
|
123 | 117 | name = 'ipython-console-mixin' |
@@ -1,5 +1,11 b'' | |||
|
1 | """Produce SVG versions of active plots for display by the rich Qt frontend. | |
|
2 | """ | |
|
1 | """A matplotlib backend for publishing figures via display_data""" | |
|
2 | #----------------------------------------------------------------------------- | |
|
3 | # Copyright (C) 2011 The IPython Development Team | |
|
4 | # | |
|
5 | # Distributed under the terms of the BSD License. The full license is in | |
|
6 | # the file COPYING, distributed as part of this software. | |
|
7 | #----------------------------------------------------------------------------- | |
|
8 | ||
|
3 | 9 | #----------------------------------------------------------------------------- |
|
4 | 10 | # Imports |
|
5 | 11 | #----------------------------------------------------------------------------- |
@@ -7,80 +13,14 b' from __future__ import print_function' | |||
|
7 | 13 | |
|
8 | 14 | # Third-party imports |
|
9 | 15 | import matplotlib |
|
10 |
from matplotlib.backends.backend_agg import |
|
|
16 | from matplotlib.backends.backend_agg import FigureCanvasAgg | |
|
11 | 17 | from matplotlib._pylab_helpers import Gcf |
|
12 | 18 | |
|
13 |
# Local imports |
|
|
14 | from IPython.config.configurable import SingletonConfigurable | |
|
19 | # Local imports | |
|
20 | from IPython.core.getipython import get_ipython | |
|
15 | 21 | from IPython.core.display import display |
|
16 | from IPython.core.displaypub import publish_display_data | |
|
17 | from IPython.core.pylabtools import print_figure, select_figure_format | |
|
18 | from IPython.utils.traitlets import Dict, Instance, CaselessStrEnum, Bool | |
|
19 | from IPython.utils.warn import warn | |
|
20 | ||
|
21 | #----------------------------------------------------------------------------- | |
|
22 | # Configurable for inline backend options | |
|
23 | #----------------------------------------------------------------------------- | |
|
24 | # inherit from InlineBackendConfig for deprecation purposes | |
|
25 | class InlineBackendConfig(SingletonConfigurable): | |
|
26 | pass | |
|
27 | ||
|
28 | class InlineBackend(InlineBackendConfig): | |
|
29 | """An object to store configuration of the inline backend.""" | |
|
30 | ||
|
31 | def _config_changed(self, name, old, new): | |
|
32 | # warn on change of renamed config section | |
|
33 | if new.InlineBackendConfig != old.InlineBackendConfig: | |
|
34 | warn("InlineBackendConfig has been renamed to InlineBackend") | |
|
35 | super(InlineBackend, self)._config_changed(name, old, new) | |
|
36 | ||
|
37 | # The typical default figure size is too large for inline use, | |
|
38 | # so we shrink the figure size to 6x4, and tweak fonts to | |
|
39 | # make that fit. | |
|
40 | rc = Dict({'figure.figsize': (6.0,4.0), | |
|
41 | # play nicely with white background in the Qt and notebook frontend | |
|
42 | 'figure.facecolor': 'white', | |
|
43 | 'figure.edgecolor': 'white', | |
|
44 | # 12pt labels get cutoff on 6x4 logplots, so use 10pt. | |
|
45 | 'font.size': 10, | |
|
46 | # 72 dpi matches SVG/qtconsole | |
|
47 | # this only affects PNG export, as SVG has no dpi setting | |
|
48 | 'savefig.dpi': 72, | |
|
49 | # 10pt still needs a little more room on the xlabel: | |
|
50 | 'figure.subplot.bottom' : .125 | |
|
51 | }, config=True, | |
|
52 | help="""Subset of matplotlib rcParams that should be different for the | |
|
53 | inline backend.""" | |
|
54 | ) | |
|
55 | ||
|
56 | figure_format = CaselessStrEnum(['svg', 'png', 'retina'], default_value='png', config=True, | |
|
57 | help="The image format for figures with the inline backend.") | |
|
58 | ||
|
59 | def _figure_format_changed(self, name, old, new): | |
|
60 | if self.shell is None: | |
|
61 | return | |
|
62 | else: | |
|
63 | select_figure_format(self.shell, new) | |
|
64 | ||
|
65 | close_figures = Bool(True, config=True, | |
|
66 | help="""Close all figures at the end of each cell. | |
|
67 | ||
|
68 | When True, ensures that each cell starts with no active figures, but it | |
|
69 | also means that one must keep track of references in order to edit or | |
|
70 | redraw figures in subsequent cells. This mode is ideal for the notebook, | |
|
71 | where residual plots from other cells might be surprising. | |
|
72 | ||
|
73 | When False, one must call figure() to create new figures. This means | |
|
74 | that gcf() and getfigs() can reference figures created in other cells, | |
|
75 | and the active figure can continue to be edited with pylab/pyplot | |
|
76 | methods that reference the current active figure. This mode facilitates | |
|
77 | iterative editing of figures, and behaves most consistently with | |
|
78 | other matplotlib backends, but figure barriers between cells must | |
|
79 | be explicit. | |
|
80 | """) | |
|
81 | ||
|
82 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
|
83 | 22 | |
|
23 | from .config import InlineBackend | |
|
84 | 24 | |
|
85 | 25 | #----------------------------------------------------------------------------- |
|
86 | 26 | # Functions |
@@ -107,7 +47,6 b' def show(close=None):' | |||
|
107 | 47 | matplotlib.pyplot.close('all') |
|
108 | 48 | |
|
109 | 49 | |
|
110 | ||
|
111 | 50 | # This flag will be reset by draw_if_interactive when called |
|
112 | 51 | show._draw_called = False |
|
113 | 52 | # list of figures to draw when flush_figures is called |
General Comments 0
You need to be logged in to leave comments.
Login now