如何使用matplotlib在单个页面上绘制多个图? [英] How to make several plots on a single page using matplotlib?
问题描述
我写的代码可以一次打开16位数字.目前,它们都以单独的图形打开.我希望他们在同一页面上全部打开.不一样的图.我希望在单个页面/窗口上有16个独立的图.同样由于某种原因,numbins和defaultreallimits的格式也无法保存在图1之上.是否需要使用subplot命令?我不明白为什么我必须这样做,但不知道我还要做什么?
I have written code that opens 16 figures at once. Currently they all open as separate graphs. I'd like them to open all on the same page. Not the same graph. I want 16 separate graphs on a single page/window. Also for some reason the format of the numbins and defaultreallimits doesn't hold past figure 1. Do I need to use the subplot command? I don't understand why I would have to but can't figure out what else I would do?
import csv
import scipy.stats
import numpy
import matplotlib.pyplot as plt
for i in range(16):
plt.figure(i)
filename= easygui.fileopenbox(msg='Pdf distance 90m contour', title='select file', filetypes=['*.csv'], default='X:\\herring_schools\\')
alt_file=open(filename)
a=[]
for row in csv.DictReader(alt_file):
a.append(row['Dist_90m(nmi)'])
y= numpy.array(a, float)
relpdf=scipy.stats.relfreq(y, numbins=7, defaultreallimits=(-10,60))
bins = numpy.arange(-10,60,10)
print numpy.sum(relpdf[0])
print bins
patches=plt.bar(bins,relpdf[0], width=10, facecolor='black')
titlename= easygui.enterbox(msg='write graph title', title='', default='', strip=True, image=None, root=None)
plt.title(titlename)
plt.ylabel('Probability Density Function')
plt.xlabel('Distance from 90m Contour Line(nm)')
plt.ylim([0,1])
plt.show()
推荐答案
To answer your main question, you want to use the subplot command. I think changing plt.figure(i)
to plt.subplot(4,4,i+1)
should work.
这篇关于如何使用matplotlib在单个页面上绘制多个图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!