2017-08-15 63 views
0

如何限制matplotlib圖中y軸的高度?我正在嘗試顯示x軸,並降低此一維圖的高度。如何限制matplotlib中的y軸高度?

我已經嘗試設置蜱,圖尺寸,tight_layout,邊距等,沒有運氣。

另外,無論我選擇什麼限制,更改ylimits只是跨越整個身高。

import numpy as np 
import matplotlib.pyplot as plot 
from matplotlib import rcParams 

x = np.array([3500]) 
y = np.array([0]) 

rcParams['toolbar'] = 'None' 

plot.figure(num=None, figsize=(4, 1), dpi=80, facecolor='w') 
plot.axes(frameon=False) 
plot.yticks([0]) 
plot.xlim(0, 6000) 
plot.ylim(-0.1, 0.1) 
plot.plot(x, y, 'x', markersize=10) 

plot.show() 

Current figure

Desired figure

回答

0

簡單地改變figsize(4, 0.3),我得到的東西,或多或少看起來像你期望的輸出(除了在頂部蜱爲好,但這些也可以去掉):

Output

+0

你在Windows上嗎?當我在Windows上運行它時,它仍然會爲我削減底部軸標記。 – vaderade

+0

是的,那是在Windows上。如果你把'figsize'(5,0.5)'和'plot.gcf()。subplots_adjust(bottom = 0.5)'結合起來怎麼辦? – fuglede

+0

這就是我正在尋找的。謝謝! – vaderade

1

試試這個:

plot.ylim(lower_limit, upper_limit) 

哪裏lower_limit是要爲y-axisupper_limit的底部設置的值是最高值。

np.random.seed(0) 
x = np.random.randn(100) 
y = np.random.randn(100) 

plot.figure(num=None, figsize=(4, 1), dpi=80, facecolor='w') 
plot.axes(frameon=False) 
plot.ylim(-10, 10) 
plot.plot(x, y, '.') 

enter image description here

+0

我試過了,但無論限制我使用,但它仍然充滿身影。由於這只是一維情節,我希望高度縮小。 – vaderade

0

在問題中的代碼已產生所需的結果,在結尾處增加 plot.tight_layout()時。

enter image description here

當然甚至進一步降低了數字的大小,更加縮小的情節。例如。 figsize=(4, 0.7)

enter image description here