2014-03-24 18 views
1

我想產生一個日誌(基地2)陰謀,但我一直得到一個沒有頂部/底部邊界的情節。Matplotlib日誌規模與限制關閉底部/向上繪圖脊柱

import matplotlib.pyplot as plt 
from matplotlib.ticker import ScalarFormatter 

def toK (array): 
    return map (lambda x: x/1000.0, array) 


yy = [2603.76, 41077.89,48961.74, 43471.14] 
xx = [1,16,32,64] 

ax = plt.subplot(221, axisbg = 'white') 
ax.set_xlim(0, 128) 


ax.set_xscale('log', basex=2) 



ax.plot(xx, toK(yy), label="0%", linestyle='--', marker='o', clip_on = False) 

plt.savefig('./tx2.pdf', bbox_inches='tight') 

Unboder plit

我怎麼能這樣做是否正確?

回答

2

這是因爲在使用對數刻度時,您有0作爲極限。 (0在對數刻度上爲負無窮大)

將軸限制設置爲包括零應該可以引起錯誤,但此刻它只是默默地導致某些事情中斷。

如果要在圖上有0,請使用symlog而不是日誌。然而,在這種情況下,最小化爲2^-1(即0.5)可能更有意義。

例如,做這一點:

import matplotlib.pyplot as plt 
import numpy as np 

yy = np.array([2603.76, 41077.89,48961.74, 43471.14]) 
xx = [1,16,32,64] 

fig, ax = plt.subplots() 
ax.set_xlim(0.5, 128) 

ax.set_xscale('log', basex=2) 

ax.plot(xx, yy/1000, linestyle='--', marker='o', clip_on=False) 
plt.show() 

enter image description here

或使用 「symlog」,而不是對數刻度:

import matplotlib.pyplot as plt 
import numpy as np 

yy = np.array([2603.76, 41077.89,48961.74, 43471.14]) 
xx = [1,16,32,64] 

fig, ax = plt.subplots() 
ax.set_xlim(0, 128) 

ax.set_xscale('symlog', basex=2) 

ax.plot(xx, yy/1000, linestyle='--', marker='o', clip_on=False) 
plt.show() 

enter image description here

+0

我試過symlog之前但在保存繪圖時失敗。 – fabiim

+0

@fabiim - 它如何失敗?你能提供更多的細節嗎? –

+0

http://pastebin.com/bqjZUDDe(我用plt.savefig('./ tx2.png'))而不是show – fabiim