2014-02-27 65 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) 

但它听起来就像你可能指的是对脊椎蜱...