首页 > 解决方案 > matplotlib 子图未显示

问题描述

右列图没有出现,知道发生了什么吗?我可以将它们堆叠在一起,但是当我尝试制作两列时,右侧的列不显示。另外,当我尝试使用 %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()

在此处输入图像描述

标签: pythonmatplotlibggplot2plotrows

解决方案


您正在使用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))

推荐阅读