2013-07-24 17 views
6

在由matplotlib.pyplot創建的圖中,如何強制軸標籤以指數表示法顯示?這似乎是自動完成的值爲< 1e-6,但對於比如說5e-6,我得到「0.000005」。我更希望在這個範圍內顯示爲「5e-6」。Matplotlib.pyplot:力指數軸標籤記號

+0

http://matplotlib.org/api/ticker_api.html#matplotlib.ticker.FormatStrFormatter' 「%E」'是指數 –

回答

5

似乎像你應該能夠設置軸的ScalarFormatter的功率限制。 (未經測試的代碼)

# Set limits to x < 10^1 and x > 10^-1 
# (overlapping, thus all inclusive, hopefully) 
gca().get_yaxis().get_major_formatter().set_powerlimits((0, 0)) 
+3

你可以做一個更好的,只是調用'set_powerlimits'上'gca()。get_major_formatter()' – tacaswell

+0

@tcaswell:很好,謝謝。 – voithos

+1

@voithos:我不得不使用'gca()。yaxis.get_major_formatter()。set_powerlimits(( - 1,1))''。是否有一種(優雅的)方式將變更應用於兩個座標軸? @tcaswell:你是如何做到這一點的?在沒有參數的情況下調用'set_powerlimits'會導致錯誤。 – gandi2223