出于一个奇怪的原因,我找不到在Python的matplotlibrc文件中指定spine配置的方式。任何想法如何导致matplotlib不默认绘制上部和右侧脊柱? spines http://matplotlib.sourceforge.net/_images/whats_new_99_spines.png在matplotlibrc中设置尖刺
更多关于matplotlib刺信息是here
谢谢
出于一个奇怪的原因,我找不到在Python的matplotlibrc文件中指定spine配置的方式。任何想法如何导致matplotlib不默认绘制上部和右侧脊柱? spines http://matplotlib.sourceforge.net/_images/whats_new_99_spines.png在matplotlibrc中设置尖刺
更多关于matplotlib刺信息是here
谢谢
为了躲右和插曲的顶刺,你需要在两个设置相关刺的颜色'none'
,以及为xtick设置刻度位置为'left'
,为ytick设置'bottom'
(以便隐藏刻度标记以及脊椎)。
不幸的是,目前还没有人可以通过matplotlibrc
访问。在matplotlibrc
中指定的参数经过验证,然后存储在一个名为rcParams
的字典中。然后由单个模块检查该字典中的一个键,其值将作为其默认值。如果他们没有检查他们的选项之一,则该选项不能通过rc
文件更改。
由于rc
系统的性质,以及刺的编写方式,改变代码,允许这不会是简单的:
棘目前通过用于定义相同rc
参数获得它们的颜色轴颜色;您不能将其设置为'none'
而不隐藏所有轴图。他们也不知道他们是否是top
,right
,left
或bottom
—这些实际上只是存储在字典中的四个独立的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
中增加对所需选项的支持。
要matplotlib不要画上,右刺,一个可以设置matplotlibrc文件
axes.spines.right : False
axes.spines.top : False
以下您也可以卸载从顶部和右轴从matplotlibrc文件蜱? – jkokorian 2016-11-08 13:39:24
@jkokorian:在即将发布的matplotlib 2.0.0版本中,您可以设置'xtick.top'和'ytick.right'选项。 – Roun 2016-11-08 22:13:59