Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In order to hide the right and top spines of a subplot, you need to both set the colour of the relevant spines to <code>'none'</code>, as well as set the tick position to <code>'left'</code> for the xtick, and <code>'bottom'</code> for the ytick (in order to hide the tick marks as well as the spines).</p> <p>Unfortunately, none of these are currently accessible via <code>matplotlibrc</code>. The parameters specified in <code>matplotlibrc</code> are validated, and then stored in a dict called <code>rcParams</code>. It is then up to the individual modules to check for a key in this dict whose value will act as their default. If they don't check it for one of their options, that option is not alterable via the <code>rc</code> file. </p> <p>Due to the nature of the <code>rc</code> system, and the way that spines are written, altering the code to allow for this would not be straightforward:</p> <p>Spines currently obtain their colour through the same <code>rc</code> parameter used to define axis colours; you cannot set it to <code>'none'</code> without hiding all of your axis drawing. They are also agnostic towards whether they are <code>top</code>, <code>right</code>, <code>left</code>, or <code>bottom</code> &mdash; these are really just four separate spines stored in a dict. The individual spine objects do not know what side of the plot they compose, so you cannot just add new <code>rc</code> params and assign the proper one during spine initialization.</p> <pre><code>self.set_edgecolor( rcParams['axes.edgecolor'] ) </code></pre> <p>(<em>./matplotlib/lib/matplotlib/spines.py</em>, __init__(), <em>line 54</em>)</p> <p>If you have a large amount of existing code, such that adding the axis parameters manually to each one would be too burdensome, you could alternately use a helper function to iterate through all of the Axis objects and set the values for you.</p> <p>Here's an example:</p> <pre><code>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() </code></pre> <p>Just call <code>hide_spines()</code> before <code>show()</code>, and it will hide them in all of the figures that <code>show()</code> displays. I cannot think of a simpler way to alter a large number of figures, outside of spending the time to patch <code>matplotlib</code> and add in <code>rc</code> support for the needed options. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload