Deprecation warnings with Matplotlib 3.4
Matplotlib 3.4 has deprecated the canvas set_window_title method: https://matplotlib.org/stable/api/api_changes.html#backend-deprecations.
This raises the following warning when rendering 2D observers:
MatplotlibDeprecationWarning:
The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead.
A quick fix is to replace fig.canvas.set_window_title with fig.canvas.manager.set_window_title in the _render_display method of pipelines. But it seems some backends may have no manager, so perhaps a check for None should also be done: https://github.com/matplotlib/matplotlib/issues/17716/.
In addition to the fix suggested by @jacklovell, the figure can be initialised with the self.name assigned to the num argument (it accepts strings as well as the numbers). In this case, if the backend has no manager, the name assigned to the pipeline before the first observe() call will be displayed as the window title. If the pipeline name changes between the observe() calls, the window title will remain unchanged, but this is still better than nothing.
# create a fresh figure if the existing figure window has gone missing
if not self._display_figure or not plt.fignum_exists(self._display_figure.number):
self._display_figure = plt.figure(self.name, facecolor=(0.5, 0.5, 0.5), figsize=_DISPLAY_SIZE, dpi=_DISPLAY_DPI)
fig = self._display_figure
# set window title
if fig.canvas.manager is not None:
if status:
fig.canvas.manager.set_window_title("{} - {}".format(self.name, status))
else:
fig.canvas.manager.set_window_title(self.name)
Urgh. I really do want to get rid of the matplotlib dependency entirely and replace it with a proper threaded gui display. Theoretically simple to knock up in tk, but as usual I don't have to time. Thanks for identifying the issue and finding solutions.
Really? I need so many lines of nasty code just to set a window_title?
You can use fig.suptitle() which kinda behaves like set_window_title.
The set_window_title is no longer available as a canvas method in Matplotlib 3.6 and pipelines now throw an error. I think a hotfix is needed. @CnlPepper, if you are happy with https://github.com/raysect/source/issues/383#issuecomment-812037875, I can make a PR.