2014-02-27 60 views
0

我很難在繪圖中打開和關閉軸,並適當調整軸的大小。我跟着幾個線程,我的方法是:Matplotlib軸控制

f1=plt.figure(1,(3,3)) 
ax=Subplot(f1,111) 
f1.add_subplot(ax) 
ax.scatter(current,backg,label='Background Height') 
ax.plot(current,backg) 
ax.scatter(current,peak,color = 'red',label='Peak Spot Height') 
ax.plot(current,peak,color='red') 
ax.plot(current,meanspot,color='green') 
ax.scatter(current,meanspot,color = 'green',label='Mean Spot Height') 

ax.spines['left'].set_position('center') 
ax.spines['right'].set_color('none') 
ax.spines['bottom'].set_position('center') 
ax.spines['top'].set_color('none') 
ax.spines['left'].set_smart_bounds(True) 
ax.spines['bottom'].set_smart_bounds(True) 
ax.xaxis.set_ticks_position('bottom') 
ax.yaxis.set_ticks_position('left') 

但我的數字仍然在頂部和右側,和一個陌生的差距軸最終由於軸的尺寸。 enter image description here

+0

我不能完全確定你想要達到的目標,但在matplotlib網站上有[some](http://matplotlib.org/examples/ticks_and_spines/spines_demo_bounds.html)[示例](http://matplotlib.org/examples/ticks_and_spines/spines_demo.html),可以幫助你。 – Evert

回答

1

我強烈建議您查看seaborn庫以進行這種操作。去除刺就像sns.despine()一樣簡單。

例如,爲了使在白色背景上的骨氣圖我可以寫

import pandas as pd 
import numpy as np 
import seaborn as sns 

df2 = pd.Series([np.sqrt(x) for x in range(20)]) 
sns.set(style="nogrid") 
df2.plot() 
sns.despine(left=True, bottom=True) 

得到

enter image description here

看一看有關更多詳細信息鏈接的文檔。它確實使控制matplotlib美學工作比手動編寫所有代碼更容易。

0

你能更具體什麼需要?

您可以刪除脊柱:

ax.spines['right'].set_visible(False) 
ax.spines['top'].set_visible(False) 
ax.spines['left'].set_visible(False) 
ax.spines['bottom'].set_visible(False) 

但它聽起來就像你可能指的是對脊椎蜱...