source icon indicating copy to clipboard operation
source copied to clipboard

Deprecation warnings with Matplotlib 3.4

Open jacklovell opened this issue 4 years ago • 4 comments

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/.

jacklovell avatar Apr 01 '21 08:04 jacklovell

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)

vsnever avatar Apr 01 '21 16:04 vsnever

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.

CnlPepper avatar Apr 13 '21 18:04 CnlPepper

Really? I need so many lines of nasty code just to set a window_title?

Harold0 avatar Jul 11 '21 08:07 Harold0

You can use fig.suptitle() which kinda behaves like set_window_title.

See: matplotlib.pyplot.suptitle

ktoda-code avatar Sep 29 '22 21:09 ktoda-code

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.

vsnever avatar Nov 09 '22 07:11 vsnever