Show More
@@ -117,13 +117,32 b' def draw_if_interactive():' | |||
|
117 | 117 | """ |
|
118 | 118 | Is called after every pylab drawing command |
|
119 | 119 | """ |
|
120 |
# signal that the current active figure should be sent at the end of |
|
|
121 |
# Also sets the _draw_called flag, signaling that there will be |
|
|
122 |
# At the end of the code execution, a separate call to |
|
|
123 | # will act upon these values | |
|
124 | ||
|
120 | # signal that the current active figure should be sent at the end of | |
|
121 | # execution. Also sets the _draw_called flag, signaling that there will be | |
|
122 | # something to send. At the end of the code execution, a separate call to | |
|
123 | # flush_figures() will act upon these values | |
|
124 | ||
|
125 | 125 | fig = Gcf.get_active().canvas.figure |
|
126 | ||
|
127 | # Hack: matplotlib FigureManager objects in interacive backends (at least | |
|
128 | # in some of them) monkeypatch the figure object and add a .show() method | |
|
129 | # to it. This applies the same monkeypatch in order to support user code | |
|
130 | # that might expect `.show()` to be part of the official API of figure | |
|
131 | # objects. | |
|
132 | # For further reference: | |
|
133 | # https://github.com/ipython/ipython/issues/1612 | |
|
134 | # https://github.com/matplotlib/matplotlib/issues/835 | |
|
126 | 135 | |
|
136 | if not hasattr(fig, 'show'): | |
|
137 | # Queue up `fig` for display | |
|
138 | fig.show = lambda *a: send_figure(fig) | |
|
139 | ||
|
140 | # If matplotlib was manually set to non-interactive mode, this function | |
|
141 | # should be a no-op (otherwise we'll generate duplicate plots, since a user | |
|
142 | # who set ioff() manually expects to make separate draw/show calls). | |
|
143 | if not matplotlib.is_interactive(): | |
|
144 | return | |
|
145 | ||
|
127 | 146 | # ensure current figure will be drawn, and each subsequent call |
|
128 | 147 | # of draw_if_interactive() moves the active figure to ensure it is |
|
129 | 148 | # drawn last |
@@ -132,9 +151,11 b' def draw_if_interactive():' | |||
|
132 | 151 | except ValueError: |
|
133 | 152 | # ensure it only appears in the draw list once |
|
134 | 153 | pass |
|
154 | # Queue up the figure for drawing in next show() call | |
|
135 | 155 | show._to_draw.append(fig) |
|
136 | 156 | show._draw_called = True |
|
137 | 157 | |
|
158 | ||
|
138 | 159 | def flush_figures(): |
|
139 | 160 | """Send all figures that changed |
|
140 | 161 | |
@@ -184,7 +205,7 b' def flush_figures():' | |||
|
184 | 205 | |
|
185 | 206 | |
|
186 | 207 | def send_figure(fig): |
|
187 |
"""Draw the |
|
|
208 | """Draw the given figure and send it as a PNG payload. | |
|
188 | 209 | """ |
|
189 | 210 | fmt = InlineBackend.instance().figure_format |
|
190 | 211 | data = print_figure(fig, fmt) |
General Comments 0
You need to be logged in to leave comments.
Login now