matplotlib.pyplot.subplot() -如何设置图形的名称?

时间:2021-09-27 23:40:04

When I create a single plot using the figure()-function of PyPlot, I can set the name of the appearing window using a string as argument:

当我使用PyPlot的figure()函数创建一个图时,我可以使用字符串作为参数设置出现窗口的名称:

import matplotlib.pyplot as plt
figure = plt.figure('MyName')

The function plt.subplots() doesn´t accept strings as first argument. For example:

函数plt.subplots()并´t接受字符串作为第一个参数。例如:

plt.subplots(2,2)  # for creating a window with 4 subplots

So how can I set the name of the figure?

那么我如何设置图形的名称呢?

3 个解决方案

#1


13  

Taken from the docs:

从文档:

import matplotlib.pyplot as plt

#...

# Just a figure and one subplot
f, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple plot')

And, to change the title of the Window:

并更改窗口的标题:

import matplotlib.pyplot as plt 
fig = plt.figure() 
fig.canvas.set_window_title('My Window Title') 
plt.show() 

#2


3  

plt.subplots() passes additional keyword arguments to plt.figure. Therefore, the num keyword will do what you want.

subplot()将附加的关键字参数传递给pl .figure。因此,num关键字将实现您想要的功能。

plt.subplots(2, 2, num='MyName')

You can also set figsize and dpi etc. in this way too (see plt.figure docs).

您也可以用这种方式设置figsize和dpi等(参见plt)。图文档)。

#3


0  

You can also do this:

你也可以这样做:

f, axarr = plt.subplots(2,2, num = PlotName)

where PlotName is a string and thus you can generate a window name upon instantiation

PlotName是字符串,因此可以在实例化时生成窗口名

#1


13  

Taken from the docs:

从文档:

import matplotlib.pyplot as plt

#...

# Just a figure and one subplot
f, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple plot')

And, to change the title of the Window:

并更改窗口的标题:

import matplotlib.pyplot as plt 
fig = plt.figure() 
fig.canvas.set_window_title('My Window Title') 
plt.show() 

#2


3  

plt.subplots() passes additional keyword arguments to plt.figure. Therefore, the num keyword will do what you want.

subplot()将附加的关键字参数传递给pl .figure。因此,num关键字将实现您想要的功能。

plt.subplots(2, 2, num='MyName')

You can also set figsize and dpi etc. in this way too (see plt.figure docs).

您也可以用这种方式设置figsize和dpi等(参见plt)。图文档)。

#3


0  

You can also do this:

你也可以这样做:

f, axarr = plt.subplots(2,2, num = PlotName)

where PlotName is a string and thus you can generate a window name upon instantiation

PlotName是字符串,因此可以在实例化时生成窗口名