我使用mpl_toolkits.axes_grid1
创建了下图:
但出于某种原因,我的子标题标题没有出现。我该怎么办呢?
代码:
# import
from mpl_tookits.axes_grid1 import ImageGrid
from matplotlib.pyplot import *
fig = figure(figsize=(20, 12), dpi=300)
grid = ImageGrid(fig, 111, nrows_ncols=(3, 4), axes_pad=1, aspect=False)
for gridax, (i, sub) in zip(grid, enumerate(eyelink_data)):
subnum = i + start_with
# format data
xdat = sub['x'][(sub['in_trl'] == True) & (sub['x'].notnull()) & (sub['y'].notnull())]
ydat = sub['y'][(sub['in_trl'] == True) & (sub['x'].notnull()) & (sub['y'].notnull())]
# plot
gridax.hist2d(xdat, ydat, bins=[np.linspace(-.005, .005, num=1000), np.linspace(-.005, .005, num=1000)])
gridax.plot(0, 0, 'ro') # origin
title('Subject {0} in-Trial Gaze'.format(subnum))
xlabel('Horizontal Offset\n(degrees visual angle)')
ylabel('Vertical Offset\n(degrees visual angle)')
show()
P.S。:享受grid illusion!
答案 0 :(得分:4)
如果您想要每个子图的标题,您只需对该轴使用title命令即可。你在哪里:
title('Subject {0} in-Trial Gaze'.format(subnum))
只需写下:
gridax.set_title('Subject {0} in-Trial Gaze'.format(subnum))
如果您想要一个大的xlabel
和ylabel
,则必须围绕网格制作一个大的axes
对象。我不是专家,但这应该有所帮助: