2016-04-22 54 views
0

如何在有圖形和兩個子圖時獲取色條。我想要爲所有子圖分開配色條。 對於實施例色條與子圖

fig = plt.figure() 
ax1 = fig.add_subplot(121) 
ax2 = fig.add_subplot(122) 
ax1.set_title('PC') 
ax2.set_title('MC') 
im=ax1.imshow(topo.sim.PC.activity,interpolation='nearest') 
im1=ax2.imshow(topo.sim.MC.activity,interpolation='nearest') 

我試圖plt.colorbar()ax1.colorbar()爲好。似乎沒有工作。 我在後面的代碼中的圖像上都有動畫。

+0

你試過'plt.colorbar(ax = ax1)'嗎? –

+0

是的,我嘗試了'imshow()'之後。給我一個錯誤。 – Hima

+0

在Stack Overflow上有超過1000的聲望,你應該知道「給出錯誤」永遠不會有足夠的信息:) –

回答

1

如果您按照以下方式重寫代碼,那麼它將起作用。在使用顏色條時,您需要指定要放置哪個軸。在matplotlib庫中查看examples時很容易理解。

fig = plt.figure() 
ax1 = fig.add_subplot(121) 
ax2 = fig.add_subplot(122) 
ax1.set_title('PC') 
ax2.set_title('MC') 
im=ax1.imshow(topo.sim.PC.activity,interpolation='nearest') 
im1=ax2.imshow(topo.sim.MC.activity,interpolation='nearest') 

plt.colorbar(im, ax=ax1) 
plt.colorbar(im1, ax=ax2) 

如果顏色條太大,可能需要使用shrink kwarg。

+0

它的工作!謝謝 :) – Hima