简体   繁体   中英

matplotlib.pyplot.subplots() - how to set the name of the figure?

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:

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

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

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

So how can I set the name of the figure?

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() 

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

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, num='MyName')

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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