Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 taskbar text for Python matplotlib figure

I'm learning Python and I do a lot of plotting using matplotlib. My main language, currently, is Matlab and I do a lot of plotting in it too. If I have a lot of plots at the same time I find it very useful to change the default text for that plot on the Windows Taskbar from the default "Figure 10" to something that tells me what the plot is about. In Matlab I use:

set(gcf,'NumberTitle','off');
set(gcf,'Name',string);

And the chosen string appears on the Window Taskbar icon for that figure. Matplotlib also, by default, just says "Figure 10" (or whatever the figure number is). Is there an equivalent in matplot lib or in Python?

like image 446
Michael McLaughlin Avatar asked May 10 '26 10:05

Michael McLaughlin


1 Answers

You can add a window title to plt.figure('My title') when you create the figure. The actual parameter name confusingly is called num, which is related to the default names being 'Figure 1', 'Figure 2' etc.. When num is a string, it will replace that default title.

To create the figure with plt.subplots, num can be given explicitly: fig, ax = plt.subplots(..., num='My title').

If the figure is already created earlier, change its window title with fig.canvas.set_window_title('My new title'). To get handle to the current figure: fig = plt.gcf().

It's this window title that will be displayed in the taskbar.

Here is an example involving a seaborn joint plot:

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

x = np.random.gamma(2, size=1000)
y = -.5 * x + np.random.normal(size=1000)

sns.jointplot(x, y, kind="hex", color="purple")
plt.gcf().canvas.set_window_title('Seaborn joint plot')
plt.show()

example plot

like image 52
JohanC Avatar answered May 12 '26 01:05

JohanC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!