I had the same problem and have, between this answer and have found the following:
Matplotlib 1.3.1 does not recognize any of these inputs as rcParams:
>>> plt.matplotlib.__version__
'1.3.1'
>>> plt.rcParams['axes.spines.top'] = False
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\<username>\Software\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\matplotlib\__init__.py", line 811, in __setitem__
See rcParams.keys() for a list of valid parameters.' % (key,))
KeyError: 'axes.spines.top is not a valid rc parameter.See rcParams.keys() for a list of valid parameters.'
Matplotlib 1.5.1 does, however:
In[1]: from matplotlib import pyplot as plt
In[2]: plt.matplotlib.__version__
Out[2]: '1.5.1'
In[3]: plt.rcParams
Out[3]:
RcParams({u'agg.path.chunksize': 0,
[...]
u'axes.spines.bottom': True,
u'axes.spines.left': True,
u'axes.spines.right': False,
u'axes.spines.top': False,
[...]
In[4]: x = np.linspace(0, 6)
...: y = np.sin(x)
...: plt.close('all')
...: plt.plot(x,y,'k-')

To remove the ticks as well, I had to removee them after the fact, using ax.tick_params(top="off", right="off")
. I did not find anything related in rcParams
.
I also tested matplotlib 2.2.3. There, the axes.spine.*
and got no ticks on the top and bottom without specifying any additional parameters. Either the entries in the matplotlibrc remove the whole axis, including tick marks, or the new ytick.right
, xtick.top
entries in the rcParams
dictionary are defaulting to False

Unfortunately, that still hides the last gridline on the right-hand side if it is exactly at the edge, even though the top gridline is shown under the same circumstances.
==> in other words:
- version 1.3.1 does not have a global switch and needs
ax.spines["top"].set_visible(False)
applied.
- 1.5.1 can remove the lines, globally, using the method Dan suggested (set
axes.spine.top
and axes.spine.right
to False
), but not the ticks, which still need the ax.tick_params()
command
- still later versions (not sure which version introduced it) also have
ytick.right
and xtick.top
settings which can be set to True
or False
to also omit the ticks on those edges.