matplotlib使直方图填充绘图区域

时间:2016-01-07 15:37:16

标签: python matplotlib histogram

我正在使用matplotlib做一个情节,我感到困扰的是我的绘图区域比直方图补丁占用的区域大。这是我的问题:

histogram is too narrow or axes too wide ?

你看,我想摆脱“23”补丁结束情节右边界之间的空白区域。

这是我的代码:

lines = (' '.join(line.strip().split()) for line in open(filename) if line.strip()) #prepare the date strings
local_dates = ( pytz.utc.localize(datetime.datetime.strptime(dt, "%Y-%m-%d %H:%M:%S.%f")).astimezone(localtz) for dt in lines )

local_dates = list(local_dates)

#plot by hour of day
bins = range(25)

n,bins,patches = plt.hist([ t.hour for t in local_dates], bins=bins )

xticks_pos = [0.5*patch.get_width() + patch.get_xy()[0] for patch in patches]

plt.xticks(xticks_pos, range(25),  ha='center')


plt.xlabel('Ora')
plt.ylabel('Numar de evenimente')

plt.title(filename, y=1.03)

fig = plt.gcf()
fig.set_size_inches(12,8)
plt.subplots_adjust(left=0, right=1, top=0.9, bottom=0.1)
plt.savefig(filename+'.by_hour.png', dpi=100,bbox_inches='tight')
plt.clf()

所以我可以让我的补丁拉伸整个情节视口以及如何?

0 个答案:

没有答案