MoT*_*GGE 10 python matplotlib
当我使用PyPlot的figure()函数创建单个图时,我可以使用字符串作为参数设置出现窗口的名称:
import matplotlib.pyplot as plt
figure = plt.figure('MyName')
Run Code Online (Sandbox Code Playgroud)
函数plt.subplots()不接受字符串作为第一个参数.例如:
plt.subplots(2,2) # for creating a window with 4 subplots
Run Code Online (Sandbox Code Playgroud)
那么如何设置图形的名称?
jrd*_*rd1 14
取自文档:
import matplotlib.pyplot as plt
#...
# Just a figure and one subplot
f, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple plot')
Run Code Online (Sandbox Code Playgroud)
并且,要更改窗口的标题:
import matplotlib.pyplot as plt
fig = plt.figure()
fig.canvas.set_window_title('My Window Title')
plt.show()
Run Code Online (Sandbox Code Playgroud)
plt.subplots()
将额外的关键字参数传递给plt.figure
. 因此,num
关键字将执行您想要的操作。
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, num='MyName')
Run Code Online (Sandbox Code Playgroud)
您还可以设置figsize
并dpi
以这种方式太等(见plt.figure
文档)。