Skip to content
Snippets Groups Projects
Verified Commit daf694cf authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Lazily apply default layout

improves zooming/scrolling performance
parent 74728908
Branches
Tags
1 merge request!66Extend simulator module
......@@ -74,10 +74,6 @@ class PlotManager:
self.legend_kw.setdefault('loc', 'upper right')
self.figure_kw.setdefault('num', f'Spectrometer {len(self.__instances) + 1}')
if not any('layout' in key for key in self.figure_kw.keys()):
# depending on the matplotlib version, this setting is either
# layout='tight' or tight_layout=True
self.figure_kw.setdefault('layout', 'tight')
if self.subplot_kw.pop('sharex', None) is not None:
warnings.warn('sharex in subplot_kw not negotiable, dropping', UserWarning)
......@@ -102,7 +98,7 @@ class PlotManager:
try:
self._fig = plt.figure(**self.figure_kw)
except TypeError:
if layout := self.figure_kw.pop('layout', False):
if layout := self.figure_kw.pop('layout', None) is not None:
# matplotlib < 3.5 doesn't support layout kwarg yet
self.figure_kw[f'{layout}_layout'] = True
elif layout is False:
......@@ -579,6 +575,13 @@ class PlotManager:
if self._leg is not None:
self._leg.remove()
if 'layout' not in self.figure_kw:
try:
self.fig.set_layout_engine('tight')
self.fig.get_layout_engine().execute(self.fig)
finally:
self.fig.set_layout_engine('none')
self.fig.canvas.draw_idle()
self.fig.canvas.flush_events()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment