Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 490
MoTSCHIGGE Avatar asked Aug 19 '14 15:08

MoTSCHIGGE


People also ask

How do you name subplots in Python?

Python3. If you use Matlab-like style in the interactive plotting, then you could use plt. gca() to get the reference of the current axes of the subplot and combine title. set_text() method to set title to the subplots in Matplotlib.

Which Pyplot function subplots is used to configure the size of the figure?

First off, the easiest way to change the size of a figure is to use the figsize argument. You can use this argument either in Pyplot's initialization or on an existing Figure object.


2 Answers

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.manager.set_window_title('My Window Title') 
plt.show() 

If you're using a Matplotlib version < 3.4, use: fig.canvas.set_window_title('My Windows Title')

Reference to deprecation (kudos to KaiserKatze).

like image 199
jrd1 Avatar answered Oct 02 '22 10:10

jrd1


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

like image 35
farleytpm Avatar answered Oct 02 '22 09:10

farleytpm