Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set matplotlib default figure window title

The default window title of a figure is figure X, where X is increased each figure.

I know how to change the title of a figure:

fig = pylab.gcf()
fig.canvas.set_window_title('Test')

But how do I change the default window title (So that it will be Test 1, Test 2 etc..)? so that I will not need to change the window title each time. I did not find a key in the mpl.rcParams

Thanks

like image 503
Oren Avatar asked Jul 11 '16 12:07

Oren


Video Answer


1 Answers

Edit: my answer does not change the defaults, as requested by OP, but provides a way to define figure title at figure creation.

When creating a figure using matplotlib.pyplot.subplots, there is an optional argument num that, even if not documented as such (as far as I could search), is later used as figure title:

import matplotlib.pyplot as plt
fig, axes = plt.subplots(nrows=2, num="some nice window title")
plt.ion()  # to make plot non-blocking, i.e. if multiple plots are launched
fig.show()

It is also used as default filename when saving the plot, which is a very neat feature.

(Caution: even if not documented, this num value is also a key to this figure. So, take care not to reuse the same value.)

And here's the result: enter image description here

like image 178
Joël Avatar answered Nov 03 '22 23:11

Joël