matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.57k stars 226 forks source link

set_window_title? #267

Open paugier opened 3 years ago

paugier commented 3 years ago

I'd like to change the default file name when saving a figure.

I tried with ax.figure.canvas.set_window_title(new_name), but

  1. the window title is not correctly changed and

  2. the default saving name is always "Figure n".

tacaswell commented 3 years ago

Can you please tell us what version of mpl, ~what backend~, and what version of Python you are using? Can you also give us a complete, but minimal, example of what you tried that did not work? There is a lot of state associated with GUI windows so the closer we can get to recreating exactly what is going wrong for you the easier it will be to debug.

tacaswell commented 3 years ago

I failed at reading and thought this was an issues against core Matplotlib :sheep: . in this case the backend you are using is clear from context, but a minimal example is still very helpful.

paugier commented 3 years ago

I tried something very simple:

%matplotlib widget
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fig.canvas.set_window_title("new name")

With

$ jupyter --version                       
jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : 4.7.3
ipython          : 7.18.1
ipykernel        : 5.2.1
jupyter client   : 6.1.3
jupyter lab      : 2.2.2
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.6
traitlets        : 4.3.3
$ python --version                        
Python 3.8.2
$ pip show matplotlib                     
Name: matplotlib
Version: 3.3.2
paugier commented 3 years ago

Note that it seems that the window title is reset to Figure 1 at the end of the notebook or when the figure is plotted because if I execute again fig.canvas.set_window_title("new name") (after the first execution of the notebook) the title is correctly changed.

tacaswell commented 3 years ago

That sounds like there is some state which is getting out of sync and then getting "fixed". Both the Figure and the Manager have a notion of what the name is....