Show More
@@ -17,7 +17,7 b' from matplotlib._pylab_helpers import Gcf' | |||||
17 | from IPython.config.configurable import SingletonConfigurable |
|
17 | from IPython.config.configurable import SingletonConfigurable | |
18 | from IPython.core.displaypub import publish_display_data |
|
18 | from IPython.core.displaypub import publish_display_data | |
19 | from IPython.lib.pylabtools import print_figure, select_figure_format |
|
19 | from IPython.lib.pylabtools import print_figure, select_figure_format | |
20 | from IPython.utils.traitlets import Dict, Instance, CaselessStrEnum |
|
20 | from IPython.utils.traitlets import Dict, Instance, CaselessStrEnum, CBool | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Configurable for inline backend options |
|
22 | # Configurable for inline backend options | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
@@ -47,6 +47,23 b' class InlineBackendConfig(SingletonConfigurable):' | |||||
47 | return |
|
47 | return | |
48 | else: |
|
48 | else: | |
49 | select_figure_format(self.shell, new) |
|
49 | select_figure_format(self.shell, new) | |
|
50 | ||||
|
51 | close_figures = CBool(True, config=True, | |||
|
52 | help="""Close all figures at the end of each cell. | |||
|
53 | ||||
|
54 | When True, ensures that each cell starts with no active figures, but it | |||
|
55 | also means that one must keep track of references in order to edit or | |||
|
56 | redraw figures in subsequent cells. This mode is ideal for the notebook, | |||
|
57 | where residual plots from other cells might be surprising. | |||
|
58 | ||||
|
59 | When False, one must call figure() to create new figures. This means | |||
|
60 | that gcf() and getfigs() can reference figures created in other cells, | |||
|
61 | and the active figure can continue to be edited with pylab/pyplot | |||
|
62 | methods that reference the current active figure. This mode facilitates | |||
|
63 | iterative editing of figures, and behaves most consistently with | |||
|
64 | other matplotlib backends, but figure barriers between cells must | |||
|
65 | be explicit. | |||
|
66 | """) | |||
50 |
|
67 | |||
51 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') |
|
68 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
52 |
|
69 | |||
@@ -55,8 +72,8 b' class InlineBackendConfig(SingletonConfigurable):' | |||||
55 | # Functions |
|
72 | # Functions | |
56 | #----------------------------------------------------------------------------- |
|
73 | #----------------------------------------------------------------------------- | |
57 |
|
74 | |||
58 |
def show(close= |
|
75 | def show(close=None): | |
59 | """Show all figures as SVG payloads sent to the IPython clients. |
|
76 | """Show all figures as SVG/PNG payloads sent to the IPython clients. | |
60 |
|
77 | |||
61 | Parameters |
|
78 | Parameters | |
62 | ---------- |
|
79 | ---------- | |
@@ -65,12 +82,14 b' def show(close=False):' | |||||
65 | sending all the figures. If this is set, the figures will entirely |
|
82 | sending all the figures. If this is set, the figures will entirely | |
66 | removed from the internal list of figures. |
|
83 | removed from the internal list of figures. | |
67 | """ |
|
84 | """ | |
|
85 | if close is None: | |||
|
86 | close = InlineBackendConfig.instance().close_figures | |||
68 | for figure_manager in Gcf.get_all_fig_managers(): |
|
87 | for figure_manager in Gcf.get_all_fig_managers(): | |
69 | send_figure(figure_manager.canvas.figure) |
|
88 | send_figure(figure_manager.canvas.figure) | |
70 | if close: |
|
89 | if close: | |
71 | matplotlib.pyplot.close('all') |
|
90 | matplotlib.pyplot.close('all') | |
72 | show._to_draw = [] |
|
91 | show._to_draw = [] | |
73 |
|
92 | |||
74 |
|
93 | |||
75 |
|
94 | |||
76 | # This flag will be reset by draw_if_interactive when called |
|
95 | # This flag will be reset by draw_if_interactive when called | |
@@ -109,6 +128,11 b' def flush_figures():' | |||||
109 | """ |
|
128 | """ | |
110 | if not show._draw_called: |
|
129 | if not show._draw_called: | |
111 | return |
|
130 | return | |
|
131 | ||||
|
132 | if InlineBackendConfig.instance().close_figures: | |||
|
133 | # ignore the tracking, just draw and close all figures | |||
|
134 | return show(True) | |||
|
135 | ||||
112 | # exclude any figures that were closed: |
|
136 | # exclude any figures that were closed: | |
113 | active = set([fm.canvas.figure for fm in Gcf.get_all_fig_managers()]) |
|
137 | active = set([fm.canvas.figure for fm in Gcf.get_all_fig_managers()]) | |
114 | for fig in [ fig for fig in show._to_draw if fig in active ]: |
|
138 | for fig in [ fig for fig in show._to_draw if fig in active ]: |
General Comments 0
You need to be logged in to leave comments.
Login now