直接上代码,以免忘记,用网页打开pdf,顶部会少很多内容,一直以为是代码错了,调整了好多次。
import matplotlib as mpl
mpl.use('Agg') #因为在linux中不加这2句还报错,还要在2.7画出的hist才正确
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.read_table("normal.num",header=None,nrows=500) #读取500行数据,画500个hist图
fig = plt.figure(figsize=(6*5,5*100)) #设置figure的大小,画的图是100行5列,hist的长为6,宽为5
for i in range(500):
fig.add_subplot(100,5,i+1) #在设置100行,有5列,i+1代表在这500个图的的第几个位置
plt.hist(np.array(df.ix[i,1:]),histtype='bar') #在每一个axes中画出hist的bar图
ax = plt.gca() #获取axes的对象
ax.set_title(df.ix[i,0])
plt.subplots_adjust(left=0.1,right=0.95,top=0.95,bottom=0.05) #调整整体图在pdf中的位置
plt.savefig("normal.pdf",dpi=500)
效果图如下