出于一个奇怪的原因,我找不到在Python的matplotlibrc文件中指定spines配置的方法.有关如何使matplotlib默认不绘制上右刺的任何想法? 刺http://matplotlib.sourceforge.net/_images/whats_new_99_spines.png
有关matplotlib中刺的信息的更多信息,请点击此处
谢谢
And*_*rew 17
为了隐藏子图的右侧和顶部脊柱,您需要同时设置相关脊柱的颜色,并为xtick 和ytick 'none'设置刻度位置(以隐藏刻度线)以及刺).'left''bottom'
不幸的是,目前这些都不是通过matplotlibrc.matplotlibrc验证中指定的参数,然后存储在名为的dict中rcParams.然后由各个模块检查该字典中的键,其值将作为其默认值.如果他们没有检查其中一个选项,则该选项不能通过该rc文件进行更改.
由于rc系统的性质以及棘刺的编写方式,更改代码以实现这一点并不简单:
Spines目前通过rc用于定义轴颜色的相同参数获得颜色; 如果'none'不隐藏所有轴绘图,则无法将其设置为.他们还对他们是否是不可知的top,right,left,或bottom-这些都是真的存储在一个字典只是四个独立的刺.单个脊椎对象不知道它们组成的绘图的哪一侧,因此您不能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()
只要打电话hide_spines()之前show(),它将把他们藏在所有的数字show()显示.除了花时间修补matplotlib并添加rc对所需选项的支持之外,我想不出更简单的方法来改变大量的数字.  
Rou*_*oun 13
要使matplotlib不绘制上部和右侧脊柱,可以在matplotlibrc文件中设置以下内容
axes.spines.right : False
axes.spines.top : False