下面是我用matplotlib創建的圖。問題非常明顯 - 標籤重疊,整個事情變得難以理解。我可以對這些子圖中的重疊標籤做些什麼?
我打過電話tight_layout
每個插曲,但這個我崩潰的IPython筆記本內核。
我該如何解決佈局問題?可接受的方法包括修復每個子圖的xlabel,ylabel和標題,但另一種(也許更好)的方法是爲整個圖提供單個xlabel,ylabel和標題。
這是我用來產生上述次要情節的循環:
for i, sub in enumerate(datalist):
subnum = i + start_with
subplot(3, 4, i)
# format data (sub is a PANDAS dataframe)
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
hist2d(xdat, ydat, bins=1000)
plot(0, 0, 'ro') # origin
title('Subject {0} in-Trial Gaze'.format(subnum))
xlabel('Horizontal Offset (degrees visual angle)')
ylabel('Vertical Offset (degrees visual angle)')
xlim([-.005, .005])
ylim([-.005, .005])
# tight_layout # crashes ipython-notebook kernel
show()
更新:
好了,所以ImageGrid
似乎是要走的路,但我的身材還是找了一下靠不住的:
這是我使用的代碼:
fig = figure(dpi=300)
grid = ImageGrid(fig, 111, nrows_ncols=(3, 4), axes_pad=0.1)
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=1000)
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)')
xlim([-.005, .005])
ylim([-.005, .005])
show()
有一個食譜例如:http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label(幾個實例中,實際上) – 2013-03-15 20:53:32
fyi:應該在圖形實例上調用'tight_layout',而不是座標軸。然而,ImageGrid是最好的選擇,IMO – 2013-03-15 22:53:19
@PaulH,對了。好的趕上!謝謝!編輯:說,你會認爲這會引發一個明確的例外=/ – blz 2013-03-15 23:10:29