2010-08-09 38 views

回答

15

为了躲右和插曲的顶刺,你需要在两个设置相关刺的颜色'none',以及为xtick设置刻度位置为'left',为ytick设置'bottom'(以便隐藏刻度标记以及脊椎)。

不幸的是,目前还没有人可以通过matplotlibrc访问。在matplotlibrc中指定的参数经过验证,然后存储在一个名为rcParams的字典中。然后由单个模块检查该字典中的一个键,其值将作为其默认值。如果他们没有检查他们的选项之一,则该选项不能通过rc文件更改。

由于rc系统的性质,以及刺的编写方式,改变代码,允许这不会是简单的:

棘目前通过用于定义相同rc参数获得它们的颜色轴颜色;您不能将其设置为'none'而不隐藏所有轴图。他们也不知道他们是否是toprightleftbottom —这些实际上只是存储在字典中的四个独立的spine。单独的脊柱物体不知道它们组成的图的哪一侧,所以您不能只在脊柱初始化期间添加新的rc参数并指定适当的一个。

self.set_edgecolor(rcParams['axes.edgecolor']) 

./matplotlib/lib/matplotlib/spines.py,__init __(),线54

如果有大量的现有代码,使得将所述轴对每个参数手动设置参数会太麻烦,您可以交替使用辅助函数遍历所有Axis对象并为您设置值。

下面是一个例子:

import matplotlib 
import matplotlib.pyplot as plt 
import numpy as np 
from matplotlib.pyplot import show 

# Set up a default, sample figure. 
fig = plt.figure() 
x = np.linspace(-np.pi,np.pi,100) 
y = 2*np.sin(x) 

ax = fig.add_subplot(1,2,2) 
ax.plot(x,y) 
ax.set_title('Normal Spines') 

def hide_spines(): 
    """Hides the top and rightmost axis spines from view for all active 
    figures and their respective axes.""" 

    # Retrieve a list of all current figures. 
    figures = [x for x in matplotlib._pylab_helpers.Gcf.get_all_fig_managers()] 
    for figure in figures: 
     # Get all Axis instances related to the figure. 
     for ax in figure.canvas.figure.get_axes(): 
      # Disable spines. 
      ax.spines['right'].set_color('none') 
      ax.spines['top'].set_color('none') 
      # Disable ticks. 
      ax.xaxis.set_ticks_position('bottom') 
      ax.yaxis.set_ticks_position('left') 

hide_spines() 
show() 

show()之前只需致电hide_spines(),它会隐藏在所有的数字,show()显示器。我想不出一个更简单的方法来改变大量的数字,除了花时间来修补matplotlib并在rc中增加对所需选项的支持。

13

要matplotlib不要画上,右刺,一个可以设置matplotlibrc文件

axes.spines.right : False 
axes.spines.top : False 
+0

以下您也可以卸载从顶部和右轴从matplotlibrc文件蜱? – jkokorian 2016-11-08 13:39:24

+0

@jkokorian:在即将发布的matplotlib 2.0.0版本中,您可以设置'xtick.top'和'ytick.right'选项。 – Roun 2016-11-08 22:13:59