簡體   English   中英

將現有的 matplotlib 數字放入子圖中

[英]placing existing matplotlib figures into subplots

我想要一些關於如何安排 matplotlib.figure.Figure 對象的建議

I make an object of type 'matplotlib.figure.Figure' using the following function ( https://nilearn.github.io/modules/generated/nilearn.plotting.plot_surf_roi.html ):

from nilearn import plotting

def plot_surf(surface_data, view, fig):
    img = plotting.plot_surf_roi(surface_data['surf_mesh'], 
                        roi_map=surface_data['comp_labels'],
                        hemi=hemi, view=view,
                        cmap='RdBu_r',
                        vmax=np.nanmax(surface_data['comp_labels']), 
                        vmin=np.nanmin(surface_data['comp_labels']),
                        bg_map=surface_data['bg_maps'],
                        darkness=0.6,
                        bg_on_data=True,
                        title='',
                        figure = fig)
    return img

我想制作其中的一些並安排為子圖。 到目前為止,這是我不成功的嘗試:

fig = plt.figure()
fig, ax = plt.subplots()
plot_surf(surface_data, 'lateral', fig)
plot_surf(surface_data, 'medial', fig)
plt.show()

任何建議表示贊賞

嘗試這樣做:

def plot_surf(surface_data, view, fig, axes):
    img = plotting.plot_surf_roi(surface_data['surf_mesh'], 
                        roi_map=surface_data['comp_labels'],
                        hemi=hemi, view=view,
                        cmap='RdBu_r',
                        vmax=np.nanmax(surface_data['comp_labels']), 
                        vmin=np.nanmin(surface_data['comp_labels']),
                        bg_map=surface_data['bg_maps'],
                        darkness=0.6,
                        bg_on_data=True,
                        title='',
                        figure = fig,
                        axes=axes)
    return img

fig, (ax1, ax2) = plt.subplots(2, subplot_kw={'projection': '3d'}) 
plot_surf(surface_data, 'lateral', fig, ax1)
plot_surf(surface_data, 'medial', fig, ax2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM