Skip to content

Commit

Permalink
Avoid duplication of plots when using ipympl
Browse files Browse the repository at this point in the history
  • Loading branch information
vincefn committed Nov 22, 2022
1 parent cdd2475 commit 115d1ef
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pyobjcryst/powderpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ def plot(self, diff=None, hkl=None, figsize=(9, 4), fontsize_hkl=6, reset=False,
if self._plot_fig is None:
self._plot_fig = plt.figure(figsize=figsize)
elif plt.fignum_exists(self._plot_fig.number) is False:
# Somehow the figure disappeared, create a new one
self._plot_fig = plt.figure(figsize=figsize)
plt.figure(self._plot_fig.number)
else:
self._plot_fig = plt.figure(self._plot_fig.number)
plt.clf()
else:
plt.figure(figsize=figsize)
Expand Down Expand Up @@ -179,7 +181,8 @@ def plot(self, diff=None, hkl=None, figsize=(9, 4), fontsize_hkl=6, reset=False,
# Force immediate display. Not supported on all backends (e.g. nbagg)
plt.draw()
plt.gcf().canvas.draw()
plt.pause(.001)
if 'ipympl' not in plt.get_backend():
plt.pause(.001)
except:
pass
# plt.gca().callbacks.connect('xlim_changed', self._on_xlims_change)
Expand Down Expand Up @@ -220,7 +223,8 @@ def _do_plot_hkl(self, nb_max=100, fontsize_hkl=None):
# Force immediate display. Not supported on all backends (e.g. nbagg)
plt.draw()
plt.gcf().canvas.draw()
plt.pause(.001)
if 'ipympl' not in plt.get_backend():
plt.pause(.001)
try:
renderer = plt.gcf().canvas.renderer
except:
Expand Down

0 comments on commit 115d1ef

Please sign in to comment.