Matplotlib子图不显示了

问题描述 投票:1回答:1

右栏图不显示了,知道是怎么回事吗?我可以把它们叠加在一起,但是当我尝试制作两列时,右列不显示。另外,当我尝试%matplotlib笔记本时,图完全消失了。我已经附上了我的图的截图。

%matplotlib inline

# RING 1 PLOTS

fig, axs = plt.subplots(6, 2)
fig = plt.figure(figsize=(20,20))

axs[0,0].plot(t, ring.IN_1.soma_v, color='black', label='IN soma')
axs[0,0].plot(t, ring.IN_1.dend_prox_v, color='grey', label='IN prox dend')
axs[0,0].plot(t, ring.IN_1.dend_dist_v, color='red', label='IN dist dend')
axs[0,0].plot(t, ring.IN_1.dend_dist2_v, color='blue', label='IN dist2 dend')
axs[0,0].legend(loc='upper right', frameon=False)
axs[0,0].set_ylabel('mV')
axs[0,0].set_xticks([])
axs[0,0].set_xlim([50,300])
axs[0,0].set_ylim([-100,50])

axs[1,0].plot(t, ring.TCcells[0].soma_v, color='black', label='TC1 soma')
axs[1,0].plot(t, ring.TCcells[0].dend_prox_v, color= 'grey', label='TC1 dend')
axs[1,0].legend(frameon = False)
axs[1,0].set_ylabel('mV')
axs[1,0].set_xticks([])
axs[1,0].set_xlim([50,300])
axs[1,0].set_ylim([-100,50])

axs[2,0].plot(t, ring.TCcells[1].soma_v, color='black', label='TC2 soma')
axs[2,0].plot(t, ring.TCcells[1].dend_prox_v, color= 'grey', label='TC2 dend')
axs[2,0].legend(frameon = False)
axs[2,0].set_ylabel('mV')
axs[2,0].set_xticks([])
axs[2,0].set_xlim([50,300])
axs[2,0].set_ylim([-100,50])

axs[3,0].plot(t, ring.TCcells[2].soma_v, color='black', label='TC3 soma')
axs[3,0].plot(t, ring.TCcells[2].dend_prox_v, color= 'grey', label='TC3 dend')
axs[3,0].legend(frameon = False)
axs[3,0].set_ylabel('mV')
axs[3,0].set_xticks([])
axs[3,0].set_xlim([50,300])
axs[3,0].set_ylim([-100,50])

axs[4,0].plot(t, ring.TCcells[3].soma_v, color='black', label='TC4 soma')
axs[4,0].plot(t, ring.TCcells[3].dend_prox_v, color= 'grey', label='TC4 dend')
axs[4,0].legend(frameon = False)
axs[4,0].set_ylabel('mV')
axs[4,0].set_xticks([])
axs[4,0].set_xlim([50,300])
axs[4,0].set_ylim([-100,50])

axs[5,0].plot(t, ring.TCcells[4].soma_v, color='black', label='TC5 soma')
axs[5,0].plot(t, ring.TCcells[4].dend_prox_v, color= 'grey', label='TC5 dend')
axs[5,0].legend(frameon = False)
axs[5,0].set_ylabel('mV')
axs[5,0].set_xlabel('time (ms)')
axs[5,0].set_xlim([50,300])
axs[5,0].set_ylim([-100,50])
plt.show()

# RING 2 PLOTS
axs[0,1].plot(t, ring2.IN_1.soma_v, color='black', label='IN soma')
axs[0,1].plot(t, ring2.IN_1.dend_prox_v, color='grey', label='IN prox dend')
axs[0,1].plot(t, ring2.IN_1.dend_dist_v, color='red', label='IN dist dend')
axs[0,1].plot(t, ring2.IN_1.dend_dist2_v, color='blue', label='IN dist2 dend')
axs[0,1].legend(loc='upper right', frameon = False)
axs[0,1].set_ylabel('mV')
axs[0,1].set_xticks([]) # Use ax2's tick labels
axs[0,1].set_xlim([50,300])
axs[0,1].set_ylim([-100,50])

axs[1,1].plot(t, ring2.TCcells[0].soma_v, color='black', label='TC1 soma')
axs[1,1].plot(t, ring2.TCcells[0].dend_prox_v, color= 'grey', label='TC1 dend')
axs[1,1].legend(frameon = False)
axs[1,1].set_ylabel('mV')
axs[1,1].set_xticks([])
axs[1,1].set_xlim([50,300])
axs[1,1].set_ylim([-100,50])

axs[2,1].plot(t, ring2.TCcells[1].soma_v, color='black', label='TC2 soma')
axs[2,1].plot(t, ring2.TCcells[1].dend_prox_v, color= 'grey', label='TC2 dend')
axs[2,1].legend(frameon = False)
axs[2,1].set_ylabel('mV')
axs[2,1].set_xticks([])
axs[2,1].set_xlim([50,300])
axs[2,1].set_ylim([-100,50])

axs[3,1].plot(t, ring2.TCcells[2].soma_v, color='black', label='TC3 soma')
axs[3,1].plot(t, ring2.TCcells[2].dend_prox_v, color= 'grey', label='TC3 dend')
axs[3,1].legend(frameon = False)
axs[3,1].set_ylabel('mV')
axs[3,1].set_xticks([])
axs[3,1].set_xlim([50,300])
axs[3,1].set_ylim([-100,50])

axs[4,1].plot(t, ring2.TCcells[3].soma_v, color='black', label='TC4 soma')
axs[4,1].plot(t, ring2.TCcells[3].dend_prox_v, color= 'grey', label='TC4 dend')
axs[4,1].legend(frameon = False)
axs[4,1].set_ylabel('mV')
axs[4,1].set_xticks([])
axs[4,1].set_xlim([50,300])
axs[4,1].set_ylim([-100,50])

axs[5,1].plot(t, ring2.TCcells[4].soma_v, color='black', label='TC5 soma')
axs[5,1].plot(t, ring2.TCcells[4].dend_prox_v, color= 'grey', label='TC5 dend')
axs[5,1].legend(frameon = False)
axs[5,1].set_ylabel('mV')
axs[5,1].set_xlabel('time (ms)')
axs[5,1].set_xlim([50,300])
axs[5,1].set_ylim([-100,50])
plt.show()

enter image description here

python matplotlib ggplot2 plot rows
1个回答
1
投票

你使用的是 plt.show() 两次。去掉第一次 plt.show() 就用 曾经 在您绘制完所有数字后。

axs[5,0].set_ylim([-100,50])
plt.show()    # <------------------ Remove this one

# RING 2 PLOTS
axs[0,1].plot(t, ring2.IN_1.soma_v, color='black', label='IN soma')
.
.
.
axs[5,1].set_ylim([-100,50])
plt.show()    # <------------------ Use only this one

也可以尝试将

fig, axs = plt.subplots(6, 2)
fig = plt.figure(figsize=(20,20))

fig, axs = plt.subplots(6, 2, figsize=(20,20))
© www.soinside.com 2019 - 2024. All rights reserved.