Python 使用 plt.subplots 时的图形大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19932553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Size of figure when using plt.subplots
提问by Ashleigh Clayton
I'm having some trouble trying to change the figure size when using plt.subplots. With the following code, I just get the standard size graph with all my subplots bunched in (there's ~100) and obviously just an extra empty figuresize . I've tried using tight_layout, but to no avail.
使用plt.subplots. 使用以下代码,我只得到标准大小的图,其中包含我所有的子图(大约有 100 个),显然只是一个额外的空 figuresize 。我试过使用tight_layout,但无济于事。
def plot(reader):
channels=[]
for i in reader:
channels.append(i)
plt.figure(figsize=(50,100))
fig, ax = plt.subplots(len(channels), sharex=True)
plot=0
for j in reader:
ax[plot].plot(reader["%s" % j])
plot=plot+1
plt.tight_layout()
plt.show()
any help would be great!
任何帮助都会很棒!


采纳答案by Rutger Kassies
You can remove your initial plt.figure(). When calling plt.subplots()a new figure is created, so you first call doesn't do anything.
您可以删除初始plt.figure(). 当调用plt.subplots()一个新图形被创建时,所以你第一次调用不会做任何事情。
The subplots command in the background will call plt.figure()for you, and any keywords will be passed along. So just add the figsizekeyword to the subplots()command:
后台的 subplots 命令会调用plt.figure()你,任何关键字都会被传递。所以只需figsize在subplots()命令中添加关键字:
def plot(reader):
channels=[]
for i in reader:
channels.append(i)
fig, ax = plt.subplots(len(channels), sharex=True, figsize=(50,100))
plot=0
for j in reader:
ax[plot].plot(reader["%s" % j])
plot=plot+1
plt.tight_layout()
plt.show()

