5

以下は、matplotlib で作成した図です。問題は明らかです。ラベルが重なり合っていて、全体が判読不能です。

ここに画像の説明を入力

tight_layoutサブプロットごとに呼び出してみましたが、これにより ipython-notebook カーネルがクラッシュします。

レイアウトを修正するにはどうすればよいですか? 許容されるアプローチには、サブプロットごとに 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()
4

1 に答える 1

3

あなたが欲しいImageGridチュートリアル)。

そのリンクから直接持ち上げた最初の例 (および軽く変更したもの):

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np

im = np.arange(100)
im.shape = 10, 10

fig = plt.figure(1, (4., 4.))
grid = ImageGrid(fig, 111, # similar to subplot(111)
                nrows_ncols = (2, 2), # creates 2x2 grid of axes
                axes_pad=0.1, # pad between axes in inch.
                aspect=False, # do not force aspect='equal'
                )

for i in range(4):
    grid[i].imshow(im) # The AxesGrid object work as a list of axes.

plt.show()
于 2013-03-15T21:09:02.177 に答える