简体   繁体   English

Windows 10 任务栏文本 Python matplotlib 图

[英]Windows 10 taskbar text for Python matplotlib figure

I'm learning Python and I do a lot of plotting using matplotlib.我正在学习 Python 并且我使用 matplotlib 做了很多绘图。 My main language, currently, is Matlab and I do a lot of plotting in it too.目前,我的主要语言是 Matlab,我也在其中做了很多绘图。 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.如果我同时有很多图,我发现将Windows 任务栏上 plot的默认文本从默认的“图 10”更改为告诉我 Z32FA6E1B78A9D4028CZA4A2 是什么的内容非常有用。 In Matlab I use:在 Matlab 我使用:

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

And the chosen string appears on the Window Taskbar icon for that figure.所选字符串出现在该图的 Window 任务栏图标上。 Matplotlib also, by default, just says "Figure 10" (or whatever the figure number is). Matplotlib 默认情况下,只显示“图 10”(或任何图号)。 Is there an equivalent in matplot lib or in Python? matplot lib 或 Python 中是否有等价物?

You can add a window title to plt.figure('My title') when you create the figure .您可以在创建图形时将 window 标题添加到plt.figure('My title') 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.混淆的实际参数名称称为num ,这与默认名称为“Figure 1”、“Figure 2”等有关。当num是字符串时,它将替换该默认标题。

To create the figure with plt.subplots , num can be given explicitly: fig, ax = plt.subplots(..., num='My title') .要使用plt.subplots创建图形,可以明确给出numfig, 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') .如果之前已经创建了图窗,请将其 window 标题更改为fig.canvas.set_window_title('My new title') To get handle to the current figure: fig = plt.gcf() .要处理当前图形: fig = plt.gcf()

It's this window title that will be displayed in the taskbar.将在任务栏中显示的正是这个 window 标题。

Here is an example involving a seaborn joint plot:这是一个涉及 seaborn 接头 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()

示例图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM