2014-07-10 71 views
2

我寫了一些代碼來創建一個光柵對象的png(self [:] =一個np數組)。 它應該是一種方法,很容易做一個陰謀 代碼的問題是,它運行良好的第一次, 但是當我多次運行此方法我得到一個圖片與多個傳說。從plot中刪除顏色條(python)

enter image description here

我試圖擺脫它與delaxes,但這個傳說是真是固執。
任何想法是如何解決這個歡迎

下面的代碼:

def plot(self,image_out,dpi=150, rotate = 60): 
     xur = self.xur() 
     xll = self.xll() 
     yur = self.yur() 
     yll = self.yll() 
     fig = plt.figure() 
    #tmp = range(len(fig.axes)) 
    #tmp = tmp[::-1] 
    #for x in tmp: 
    # fig.delaxes(fig.axes[x]) 
     ax = fig.add_subplot(111) 
     cax = ax.imshow(self[:],cmap='jet', extent = [yll,yur,xll,xur], 
          interpolation = 'nearest') 
     cbar = fig.colorbar() 
     plt.xticks(rotation=70) 
     plt.tight_layout(pad = 0.25) 
     plt.savefig(image_out,dpi=dpi) 
     return 

回答

1

一個更好的選擇是指定彩條哪些軸你想看到它呈現的,看到的例子here

1

我遇到同樣的問題,並在另一篇文章的答案解決它

remove colorbar from figure in matplotlib

請參考第二個答案

我有一個類似的問題,周圍有點發揮。我想出了兩個可能略微更優雅的解決方案:

清除整個圖形並再次添加子圖(如果需要,還可以添加顏色條)。

如果始終存在一個顏色條,則可以使用自動縮放更新顏色條來更新軸。

我試過這個imshow,但我想它的作品類似的其他繪圖方法。

特別是,我用第一種方法,即清除clf()的數字,然後每次重新添加座標軸。