Skip to content

Commit 115d1ef

Browse files
committed
Avoid duplication of plots when using ipympl
1 parent cdd2475 commit 115d1ef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/pyobjcryst/powderpattern.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ def plot(self, diff=None, hkl=None, figsize=(9, 4), fontsize_hkl=6, reset=False,
121121
if self._plot_fig is None:
122122
self._plot_fig = plt.figure(figsize=figsize)
123123
elif plt.fignum_exists(self._plot_fig.number) is False:
124+
# Somehow the figure disappeared, create a new one
124125
self._plot_fig = plt.figure(figsize=figsize)
125-
plt.figure(self._plot_fig.number)
126+
else:
127+
self._plot_fig = plt.figure(self._plot_fig.number)
126128
plt.clf()
127129
else:
128130
plt.figure(figsize=figsize)
@@ -179,7 +181,8 @@ def plot(self, diff=None, hkl=None, figsize=(9, 4), fontsize_hkl=6, reset=False,
179181
# Force immediate display. Not supported on all backends (e.g. nbagg)
180182
plt.draw()
181183
plt.gcf().canvas.draw()
182-
plt.pause(.001)
184+
if 'ipympl' not in plt.get_backend():
185+
plt.pause(.001)
183186
except:
184187
pass
185188
# plt.gca().callbacks.connect('xlim_changed', self._on_xlims_change)
@@ -220,7 +223,8 @@ def _do_plot_hkl(self, nb_max=100, fontsize_hkl=None):
220223
# Force immediate display. Not supported on all backends (e.g. nbagg)
221224
plt.draw()
222225
plt.gcf().canvas.draw()
223-
plt.pause(.001)
226+
if 'ipympl' not in plt.get_backend():
227+
plt.pause(.001)
224228
try:
225229
renderer = plt.gcf().canvas.renderer
226230
except:

0 commit comments

Comments
 (0)