<p dir="auto">This feature request pertains to the following stack overflow question. <a href="http://stackoverflow.com/questions/32185411/break-in-x-axis-of-matplotlib" rel="nofollow">http://stackoverflow.com/questions/32185411/break-in-x-axis-of-matplotlib</a></p>
<p dir="auto">The answer for making a break works, however how the method works for a user should probably be abstracted away since it is not only unintuitive, but also quite lengthy for a simple break. I wish to create set_axis_break_x and set_axis_break_y functions that would take a tuple and create the break between the 2 data points without need for those long lines of code.</p>
<p dir="auto">So often times it is necessary to trim out irrelevant in information from a plot to show regions of interest, which lie far apart from each other, in higher detail, in a way that they can be easily compared. The solution to this problem is to put breaks in the axis lines (spines) to indicate a jump in magnitude.</p>
<p dir="auto">Example (from second link below):<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/20605205/42841848-a8436958-8a0b-11e8-84ba-b8b1b04f5b21.png"><img src="https://user-images.githubusercontent.com/20605205/42841848-a8436958-8a0b-11e8-84ba-b8b1b04f5b21.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">I recently had to make such plots and was disappointed by the solutions. The most predominant one seems to be <a href="https://stackoverflow.com/questions/44731152/matplotlib-create-broken-axis-in-subplot" rel="nofollow">making additional subplots, erasing the spines, and plotting fake lines to achieve the axis breaks. </a> This is the solution I used to get the plots made right now.</p>
<p dir="auto">However, I was thinking of solutions and did see <a href="https://stackoverflow.com/questions/5656798/python-matplotlib-is-there-a-way-to-make-a-discontinuous-axis" rel="nofollow">that involved creating a custom Axis subclass with it's own Transform subclass.</a> I liked this approach and decided to look a little further into it. However, this solution does not introduce the "breaks" in the axis (spine) which are critical to this display method.</p>
<p dir="auto">As such, I played with creating a subclass for the Spines to see if there was a solution for that there as well.</p>
<p dir="auto">I would like to share my code so far, just so people can see it, try it out, and offer suggestions. I'm not going directly for a PR because I'm not 100% sure where something like this should go into the code, and I would like it to be a little more polished and cohesive before starting a PR to track development. For the time being, the code only applies to the top or bottom axis, but porting to left and right is not a significant issue. I would just rather post it that let it end up forgotten in my home folder.</p>
<p dir="auto">Currently there are significant issues in the logic and drawing of the spine if the axis limits are adjusted such that the axis breaks reach the extreme end of the axes.</p>
<p dir="auto"><strong>Header</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="%matplotlib notebook

from matplotlib import pyplot as plt
from matplotlib import scale as mscale
from matplotlib import transforms as mtransforms
from matplotlib import ticker
from matplotlib import patches
from matplotlib.path import Path
from matplotlib.spines import Spine
import matplotlib.path as mpath
from matplotlib import rcParams

import numpy as np
from numpy import ma

plt.ion()"><pre class="notranslate"><span class="pl-c1">%</span><span class="pl-s1">matplotlib</span> <span class="pl-s1">notebook</span>

<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">scale</span> <span class="pl-k">as</span> <span class="pl-s1">mscale</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">transforms</span> <span class="pl-k">as</span> <span class="pl-s1">mtransforms</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">ticker</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">patches</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">path</span> <span class="pl-k">import</span> <span class="pl-v">Path</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">spines</span> <span class="pl-k">import</span> <span class="pl-v">Spine</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">path</span> <span class="pl-k">as</span> <span class="pl-s1">mpath</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">rcParams</span>

<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">from</span> <span class="pl-s1">numpy</span> <span class="pl-k">import</span> <span class="pl-s1">ma</span>

<span class="pl-s1">plt</span>.<span class="pl-en">ion</span>()</pre></div>
<p dir="auto"><strong>Axis Scale and included Transform subclass</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class BrokenScale(mscale.ScaleBase):
    name = 'broken'

    def __init__(self, axis, **kwargs):
        mscale.ScaleBase.__init__(self)
        self.thresh = None #thresh
        self.breaks = kwargs.pop('breaks', [])

    def get_transform(self):
        return self.BrokenTransform(self.breaks, self.thresh)

    def set_default_locators_and_formatters(self, axis):
        #axis.set_major_locator(BrokenScale.BrokenLocator(self.breaks))
        pass

    class BrokenTransform(mtransforms.Transform):
        input_dims = 1
        output_dims = 1
        is_separable = True

        def __init__(self, breaks, thresh):
            mtransforms.Transform.__init__(self)
            self.thresh = thresh
            self.breaks = breaks

        def transform_non_affine(self, a):
            mask = [any([low&lt;i&lt;high for (low,high) in self.breaks]) for i in a]
        
            aa = a.copy()
            tot_removed = 0
            for _range in self.breaks[::-1]:
                aa[a&gt;(_range[0])] = aa[a&gt;(_range[0])]-(_range[1]-_range[0]) + 2 # The 2 here is an offset factor so 
                                                                                 # that they points before and after the 
                                                                                 # break don't share the same x position.
                                                                                 # This will need to become a kwarg.
            mma = ma.masked_array(aa, mask)
            return mma
            
        def inverted(self):
            return BrokenScale.InvertedBrokenTransform(self.breaks, self.thresh)

    class InvertedBrokenTransform(mtransforms.Transform):
        input_dims = 1
        output_dims = 1
        is_separable = True

        def __init__(self, breaks, thresh):
            mtransforms.Transform.__init__(self)
            self.thresh = thresh
            self.breaks  = breaks

        def transform_non_affine(self, a):
            aa = a.copy()
            for _range in self.breaks:
                aa[a&gt;_range[0]] = a[a&gt;_range[0]]+(_range[1]-_range[0])
            return aa

        def inverted(self):
            return BrokenScale.BrokenTransform(self.breaks, self.thresh)
        

    class BrokenLocator(ticker.Locator):
        # To override
        
        def __init__(self):
            # To override
            pass
        def tick_values(self, vmin, vmax):
            # To override
            pass

        def __call__(self):
            # To override
            # note: some locators return data limits, other return view limits,
            # hence there is no *one* interface to call self.tick_values.
            pass"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">BrokenScale</span>(<span class="pl-s1">mscale</span>.<span class="pl-v">ScaleBase</span>):
    <span class="pl-s1">name</span> <span class="pl-c1">=</span> <span class="pl-s">'broken'</span>

    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">axis</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-s1">mscale</span>.<span class="pl-v">ScaleBase</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">self</span>)
        <span class="pl-s1">self</span>.<span class="pl-s1">thresh</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span> <span class="pl-c">#thresh</span>
        <span class="pl-s1">self</span>.<span class="pl-s1">breaks</span> <span class="pl-c1">=</span> <span class="pl-s1">kwargs</span>.<span class="pl-en">pop</span>(<span class="pl-s">'breaks'</span>, [])

    <span class="pl-k">def</span> <span class="pl-en">get_transform</span>(<span class="pl-s1">self</span>):
        <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-v">BrokenTransform</span>(<span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>, <span class="pl-s1">self</span>.<span class="pl-s1">thresh</span>)

    <span class="pl-k">def</span> <span class="pl-en">set_default_locators_and_formatters</span>(<span class="pl-s1">self</span>, <span class="pl-s1">axis</span>):
        <span class="pl-c">#axis.set_major_locator(BrokenScale.BrokenLocator(self.breaks))</span>
        <span class="pl-k">pass</span>

    <span class="pl-k">class</span> <span class="pl-v">BrokenTransform</span>(<span class="pl-s1">mtransforms</span>.<span class="pl-v">Transform</span>):
        <span class="pl-s1">input_dims</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
        <span class="pl-s1">output_dims</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
        <span class="pl-s1">is_separable</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>

        <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">breaks</span>, <span class="pl-s1">thresh</span>):
            <span class="pl-s1">mtransforms</span>.<span class="pl-v">Transform</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">self</span>)
            <span class="pl-s1">self</span>.<span class="pl-s1">thresh</span> <span class="pl-c1">=</span> <span class="pl-s1">thresh</span>
            <span class="pl-s1">self</span>.<span class="pl-s1">breaks</span> <span class="pl-c1">=</span> <span class="pl-s1">breaks</span>

        <span class="pl-k">def</span> <span class="pl-en">transform_non_affine</span>(<span class="pl-s1">self</span>, <span class="pl-s1">a</span>):
            <span class="pl-s1">mask</span> <span class="pl-c1">=</span> [<span class="pl-en">any</span>([<span class="pl-s1">low</span><span class="pl-c1">&lt;</span><span class="pl-s1">i</span><span class="pl-c1">&lt;</span><span class="pl-s1">high</span> <span class="pl-k">for</span> (<span class="pl-s1">low</span>,<span class="pl-s1">high</span>) <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>]) <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-s1">a</span>]
        
            <span class="pl-s1">aa</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span>.<span class="pl-en">copy</span>()
            <span class="pl-s1">tot_removed</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
            <span class="pl-k">for</span> <span class="pl-s1">_range</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>[::<span class="pl-c1">-</span><span class="pl-c1">1</span>]:
                <span class="pl-s1">aa</span>[<span class="pl-s1">a</span><span class="pl-c1">&gt;</span>(<span class="pl-s1">_range</span>[<span class="pl-c1">0</span>])] <span class="pl-c1">=</span> <span class="pl-s1">aa</span>[<span class="pl-s1">a</span><span class="pl-c1">&gt;</span>(<span class="pl-s1">_range</span>[<span class="pl-c1">0</span>])]<span class="pl-c1">-</span>(<span class="pl-s1">_range</span>[<span class="pl-c1">1</span>]<span class="pl-c1">-</span><span class="pl-s1">_range</span>[<span class="pl-c1">0</span>]) <span class="pl-c1">+</span> <span class="pl-c1">2</span> <span class="pl-c"># The 2 here is an offset factor so </span>
                                                                                 <span class="pl-c"># that they points before and after the </span>
                                                                                 <span class="pl-c"># break don't share the same x position.</span>
                                                                                 <span class="pl-c"># This will need to become a kwarg.</span>
            <span class="pl-s1">mma</span> <span class="pl-c1">=</span> <span class="pl-s1">ma</span>.<span class="pl-en">masked_array</span>(<span class="pl-s1">aa</span>, <span class="pl-s1">mask</span>)
            <span class="pl-k">return</span> <span class="pl-s1">mma</span>
            
        <span class="pl-k">def</span> <span class="pl-en">inverted</span>(<span class="pl-s1">self</span>):
            <span class="pl-k">return</span> <span class="pl-v">BrokenScale</span>.<span class="pl-v">InvertedBrokenTransform</span>(<span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>, <span class="pl-s1">self</span>.<span class="pl-s1">thresh</span>)

    <span class="pl-k">class</span> <span class="pl-v">InvertedBrokenTransform</span>(<span class="pl-s1">mtransforms</span>.<span class="pl-v">Transform</span>):
        <span class="pl-s1">input_dims</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
        <span class="pl-s1">output_dims</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span>
        <span class="pl-s1">is_separable</span> <span class="pl-c1">=</span> <span class="pl-c1">True</span>

        <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">breaks</span>, <span class="pl-s1">thresh</span>):
            <span class="pl-s1">mtransforms</span>.<span class="pl-v">Transform</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">self</span>)
            <span class="pl-s1">self</span>.<span class="pl-s1">thresh</span> <span class="pl-c1">=</span> <span class="pl-s1">thresh</span>
            <span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>  <span class="pl-c1">=</span> <span class="pl-s1">breaks</span>

        <span class="pl-k">def</span> <span class="pl-en">transform_non_affine</span>(<span class="pl-s1">self</span>, <span class="pl-s1">a</span>):
            <span class="pl-s1">aa</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span>.<span class="pl-en">copy</span>()
            <span class="pl-k">for</span> <span class="pl-s1">_range</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>:
                <span class="pl-s1">aa</span>[<span class="pl-s1">a</span><span class="pl-c1">&gt;</span><span class="pl-s1">_range</span>[<span class="pl-c1">0</span>]] <span class="pl-c1">=</span> <span class="pl-s1">a</span>[<span class="pl-s1">a</span><span class="pl-c1">&gt;</span><span class="pl-s1">_range</span>[<span class="pl-c1">0</span>]]<span class="pl-c1">+</span>(<span class="pl-s1">_range</span>[<span class="pl-c1">1</span>]<span class="pl-c1">-</span><span class="pl-s1">_range</span>[<span class="pl-c1">0</span>])
            <span class="pl-k">return</span> <span class="pl-s1">aa</span>

        <span class="pl-k">def</span> <span class="pl-en">inverted</span>(<span class="pl-s1">self</span>):
            <span class="pl-k">return</span> <span class="pl-v">BrokenScale</span>.<span class="pl-v">BrokenTransform</span>(<span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>, <span class="pl-s1">self</span>.<span class="pl-s1">thresh</span>)
        

    <span class="pl-k">class</span> <span class="pl-v">BrokenLocator</span>(<span class="pl-s1">ticker</span>.<span class="pl-v">Locator</span>):
        <span class="pl-c"># To override</span>
        
        <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>):
            <span class="pl-c"># To override</span>
            <span class="pl-k">pass</span>
        <span class="pl-k">def</span> <span class="pl-en">tick_values</span>(<span class="pl-s1">self</span>, <span class="pl-s1">vmin</span>, <span class="pl-s1">vmax</span>):
            <span class="pl-c"># To override</span>
            <span class="pl-k">pass</span>

        <span class="pl-k">def</span> <span class="pl-en">__call__</span>(<span class="pl-s1">self</span>):
            <span class="pl-c"># To override</span>
            <span class="pl-c"># note: some locators return data limits, other return view limits,</span>
            <span class="pl-c"># hence there is no *one* interface to call self.tick_values.</span>
            <span class="pl-k">pass</span></pre></div>
<p dir="auto"><strong>Spine subclass</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class BrokenSpine(Spine):
    def __init__(self, axes, spine_type, path, **kwargs):
        self.breaks = kwargs.pop('breaks', [])
        super().__init__(axes, spine_type, path, **kwargs)
        
    def _adjust_location(self):
        &quot;&quot;&quot;automatically set spine bounds to the view interval&quot;&quot;&quot;

        if self._bounds is None:
            if self.spine_type in ('left', 'right'):
                low, high = self.axes.viewLim.intervaly
            elif self.spine_type in ('top', 'bottom'):
                low, high = self.axes.viewLim.intervalx
            else:
                raise ValueError('unknown spine spine_type: %s' %
                                 self.spine_type)

            if self._smart_bounds:
                # attempt to set bounds in sophisticated way

                # handle inverted limits
                viewlim_low, viewlim_high = sorted([low, high])

                if self.spine_type in ('left', 'right'):
                    datalim_low, datalim_high = self.axes.dataLim.intervaly
                    ticks = self.axes.get_yticks()
                elif self.spine_type in ('top', 'bottom'):
                    datalim_low, datalim_high = self.axes.dataLim.intervalx
                    ticks = self.axes.get_xticks()
                # handle inverted limits
                ticks = np.sort(ticks)
                datalim_low, datalim_high = sorted([datalim_low, datalim_high])

                if datalim_low &lt; viewlim_low:
                    # Data extends past view. Clip line to view.
                    low = viewlim_low
                else:
                    # Data ends before view ends.
                    cond = (ticks &lt;= datalim_low) &amp; (ticks &gt;= viewlim_low)
                    tickvals = ticks[cond]
                    if len(tickvals):
                        # A tick is less than or equal to lowest data point.
                        low = tickvals[-1]
                    else:
                        # No tick is available
                        low = datalim_low
                    low = max(low, viewlim_low)

                if datalim_high &gt; viewlim_high:
                    # Data extends past view. Clip line to view.
                    high = viewlim_high
                else:
                    # Data ends before view ends.
                    cond = (ticks &gt;= datalim_high) &amp; (ticks &lt;= viewlim_high)
                    tickvals = ticks[cond]
                    if len(tickvals):
                        # A tick is greater than or equal to highest data
                        # point.
                        high = tickvals[0]
                    else:
                        # No tick is available
                        high = datalim_high
                    high = min(high, viewlim_high)

        else:
            low, high = self._bounds

        v1 = self._path.vertices
        c1 = self._path.codes
        # The below line is commented out from the copy of the parent method
        #assert v1.shape == (2, 2), 'unexpected vertices shape'
        if self.spine_type in ['left', 'right']:
            v1[0, 1] = low
            v1[1, 1] = high
        elif self.spine_type in ['bottom', 'top']:
            y = v1[0,1]
            v1 = []
            c1 = []
            v1.append([low, y])
            c1.append(Path.MOVETO)
            for i, (lower, upper) in enumerate(self.breaks):
                if lower&lt;low or upper&gt;high or lower&gt;high or upper&lt;low:
                    continue  
                c1.append(Path.LINETO)
                v1.append([lower, y])
                c1.append(Path.MOVETO)
                v1.append([upper, y])
            c1.append(Path.LINETO)
            v1.append([high, y])
            self._path = Path(v1,c1)       # Changing the number of vertices like the 
                                           # original code doesn't seem to work. 
                                           # Must create new path.

        else:
            raise ValueError('unable to set bounds for spine &quot;%s&quot;' %
                             self.spine_type)


    @classmethod
    def linear_spine(cls, axes, spine_type, **kwargs):
        &quot;&quot;&quot;
        (staticmethod) Returns a linear :class:`Spine`.
        &quot;&quot;&quot;
        breaks = kwargs.pop('breaks')
        # all values of 0.999 get replaced upon call to set_bounds()
        if spine_type == 'left':
            path = Path([(0.0, 0.999), (0.0, 0.999)])
        elif spine_type == 'right':
            path = Path([(1.0, 0.999), (1.0, 0.999)])
        elif spine_type == 'top':
            path = Path([(0.999, 1.0), (0.999, 1.0)])
        elif spine_type == 'bottom':
            verts = []
            codes = []
            low, high = axes.viewLim.intervalx
            codes.append(Path.MOVETO)
            verts.append([low, 0.0])
            for (lower, upper) in breaks:
                codes.append(Path.LINETO)
                verts.append([lower, 0.0])
                codes.append(Path.MOVETO)
                verts.append([upper, 0.0]) 
            codes.append(Path.LINETO)
            verts.append([high, 0.0])

            path = Path(verts,codes) 
            print(path)

        else:
            raise ValueError('unable to make path for spine &quot;%s&quot;' % spine_type)
            
        result = cls(axes, spine_type, path, breaks=breaks, **kwargs)
        result.set_visible(rcParams['axes.spines.{0}'.format(spine_type)])

        return result"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">BrokenSpine</span>(<span class="pl-v">Spine</span>):
    <span class="pl-k">def</span> <span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">axes</span>, <span class="pl-s1">spine_type</span>, <span class="pl-s1">path</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-s1">self</span>.<span class="pl-s1">breaks</span> <span class="pl-c1">=</span> <span class="pl-s1">kwargs</span>.<span class="pl-en">pop</span>(<span class="pl-s">'breaks'</span>, [])
        <span class="pl-en">super</span>().<span class="pl-en">__init__</span>(<span class="pl-s1">axes</span>, <span class="pl-s1">spine_type</span>, <span class="pl-s1">path</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
        
    <span class="pl-k">def</span> <span class="pl-en">_adjust_location</span>(<span class="pl-s1">self</span>):
        <span class="pl-s">"""automatically set spine bounds to the view interval"""</span>

        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">_bounds</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
            <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span> <span class="pl-c1">in</span> (<span class="pl-s">'left'</span>, <span class="pl-s">'right'</span>):
                <span class="pl-s1">low</span>, <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">axes</span>.<span class="pl-s1">viewLim</span>.<span class="pl-s1">intervaly</span>
            <span class="pl-k">elif</span> <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span> <span class="pl-c1">in</span> (<span class="pl-s">'top'</span>, <span class="pl-s">'bottom'</span>):
                <span class="pl-s1">low</span>, <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">axes</span>.<span class="pl-s1">viewLim</span>.<span class="pl-s1">intervalx</span>
            <span class="pl-k">else</span>:
                <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">'unknown spine spine_type: %s'</span> <span class="pl-c1">%</span>
                                 <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span>)

            <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">_smart_bounds</span>:
                <span class="pl-c"># attempt to set bounds in sophisticated way</span>

                <span class="pl-c"># handle inverted limits</span>
                <span class="pl-s1">viewlim_low</span>, <span class="pl-s1">viewlim_high</span> <span class="pl-c1">=</span> <span class="pl-en">sorted</span>([<span class="pl-s1">low</span>, <span class="pl-s1">high</span>])

                <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span> <span class="pl-c1">in</span> (<span class="pl-s">'left'</span>, <span class="pl-s">'right'</span>):
                    <span class="pl-s1">datalim_low</span>, <span class="pl-s1">datalim_high</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">axes</span>.<span class="pl-s1">dataLim</span>.<span class="pl-s1">intervaly</span>
                    <span class="pl-s1">ticks</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">axes</span>.<span class="pl-en">get_yticks</span>()
                <span class="pl-k">elif</span> <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span> <span class="pl-c1">in</span> (<span class="pl-s">'top'</span>, <span class="pl-s">'bottom'</span>):
                    <span class="pl-s1">datalim_low</span>, <span class="pl-s1">datalim_high</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">axes</span>.<span class="pl-s1">dataLim</span>.<span class="pl-s1">intervalx</span>
                    <span class="pl-s1">ticks</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">axes</span>.<span class="pl-en">get_xticks</span>()
                <span class="pl-c"># handle inverted limits</span>
                <span class="pl-s1">ticks</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">sort</span>(<span class="pl-s1">ticks</span>)
                <span class="pl-s1">datalim_low</span>, <span class="pl-s1">datalim_high</span> <span class="pl-c1">=</span> <span class="pl-en">sorted</span>([<span class="pl-s1">datalim_low</span>, <span class="pl-s1">datalim_high</span>])

                <span class="pl-k">if</span> <span class="pl-s1">datalim_low</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">viewlim_low</span>:
                    <span class="pl-c"># Data extends past view. Clip line to view.</span>
                    <span class="pl-s1">low</span> <span class="pl-c1">=</span> <span class="pl-s1">viewlim_low</span>
                <span class="pl-k">else</span>:
                    <span class="pl-c"># Data ends before view ends.</span>
                    <span class="pl-s1">cond</span> <span class="pl-c1">=</span> (<span class="pl-s1">ticks</span> <span class="pl-c1">&lt;=</span> <span class="pl-s1">datalim_low</span>) <span class="pl-c1">&amp;</span> (<span class="pl-s1">ticks</span> <span class="pl-c1">&gt;=</span> <span class="pl-s1">viewlim_low</span>)
                    <span class="pl-s1">tickvals</span> <span class="pl-c1">=</span> <span class="pl-s1">ticks</span>[<span class="pl-s1">cond</span>]
                    <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">tickvals</span>):
                        <span class="pl-c"># A tick is less than or equal to lowest data point.</span>
                        <span class="pl-s1">low</span> <span class="pl-c1">=</span> <span class="pl-s1">tickvals</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>]
                    <span class="pl-k">else</span>:
                        <span class="pl-c"># No tick is available</span>
                        <span class="pl-s1">low</span> <span class="pl-c1">=</span> <span class="pl-s1">datalim_low</span>
                    <span class="pl-s1">low</span> <span class="pl-c1">=</span> <span class="pl-en">max</span>(<span class="pl-s1">low</span>, <span class="pl-s1">viewlim_low</span>)

                <span class="pl-k">if</span> <span class="pl-s1">datalim_high</span> <span class="pl-c1">&gt;</span> <span class="pl-s1">viewlim_high</span>:
                    <span class="pl-c"># Data extends past view. Clip line to view.</span>
                    <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-s1">viewlim_high</span>
                <span class="pl-k">else</span>:
                    <span class="pl-c"># Data ends before view ends.</span>
                    <span class="pl-s1">cond</span> <span class="pl-c1">=</span> (<span class="pl-s1">ticks</span> <span class="pl-c1">&gt;=</span> <span class="pl-s1">datalim_high</span>) <span class="pl-c1">&amp;</span> (<span class="pl-s1">ticks</span> <span class="pl-c1">&lt;=</span> <span class="pl-s1">viewlim_high</span>)
                    <span class="pl-s1">tickvals</span> <span class="pl-c1">=</span> <span class="pl-s1">ticks</span>[<span class="pl-s1">cond</span>]
                    <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">tickvals</span>):
                        <span class="pl-c"># A tick is greater than or equal to highest data</span>
                        <span class="pl-c"># point.</span>
                        <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-s1">tickvals</span>[<span class="pl-c1">0</span>]
                    <span class="pl-k">else</span>:
                        <span class="pl-c"># No tick is available</span>
                        <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-s1">datalim_high</span>
                    <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-en">min</span>(<span class="pl-s1">high</span>, <span class="pl-s1">viewlim_high</span>)

        <span class="pl-k">else</span>:
            <span class="pl-s1">low</span>, <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_bounds</span>

        <span class="pl-s1">v1</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_path</span>.<span class="pl-s1">vertices</span>
        <span class="pl-s1">c1</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_path</span>.<span class="pl-s1">codes</span>
        <span class="pl-c"># The below line is commented out from the copy of the parent method</span>
        <span class="pl-c">#assert v1.shape == (2, 2), 'unexpected vertices shape'</span>
        <span class="pl-k">if</span> <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span> <span class="pl-c1">in</span> [<span class="pl-s">'left'</span>, <span class="pl-s">'right'</span>]:
            <span class="pl-s1">v1</span>[<span class="pl-c1">0</span>, <span class="pl-c1">1</span>] <span class="pl-c1">=</span> <span class="pl-s1">low</span>
            <span class="pl-s1">v1</span>[<span class="pl-c1">1</span>, <span class="pl-c1">1</span>] <span class="pl-c1">=</span> <span class="pl-s1">high</span>
        <span class="pl-k">elif</span> <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span> <span class="pl-c1">in</span> [<span class="pl-s">'bottom'</span>, <span class="pl-s">'top'</span>]:
            <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">v1</span>[<span class="pl-c1">0</span>,<span class="pl-c1">1</span>]
            <span class="pl-s1">v1</span> <span class="pl-c1">=</span> []
            <span class="pl-s1">c1</span> <span class="pl-c1">=</span> []
            <span class="pl-s1">v1</span>.<span class="pl-en">append</span>([<span class="pl-s1">low</span>, <span class="pl-s1">y</span>])
            <span class="pl-s1">c1</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">MOVETO</span>)
            <span class="pl-k">for</span> <span class="pl-s1">i</span>, (<span class="pl-s1">lower</span>, <span class="pl-s1">upper</span>) <span class="pl-c1">in</span> <span class="pl-en">enumerate</span>(<span class="pl-s1">self</span>.<span class="pl-s1">breaks</span>):
                <span class="pl-k">if</span> <span class="pl-s1">lower</span><span class="pl-c1">&lt;</span><span class="pl-s1">low</span> <span class="pl-c1">or</span> <span class="pl-s1">upper</span><span class="pl-c1">&gt;</span><span class="pl-s1">high</span> <span class="pl-c1">or</span> <span class="pl-s1">lower</span><span class="pl-c1">&gt;</span><span class="pl-s1">high</span> <span class="pl-c1">or</span> <span class="pl-s1">upper</span><span class="pl-c1">&lt;</span><span class="pl-s1">low</span>:
                    <span class="pl-k">continue</span>  
                <span class="pl-s1">c1</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">LINETO</span>)
                <span class="pl-s1">v1</span>.<span class="pl-en">append</span>([<span class="pl-s1">lower</span>, <span class="pl-s1">y</span>])
                <span class="pl-s1">c1</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">MOVETO</span>)
                <span class="pl-s1">v1</span>.<span class="pl-en">append</span>([<span class="pl-s1">upper</span>, <span class="pl-s1">y</span>])
            <span class="pl-s1">c1</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">LINETO</span>)
            <span class="pl-s1">v1</span>.<span class="pl-en">append</span>([<span class="pl-s1">high</span>, <span class="pl-s1">y</span>])
            <span class="pl-s1">self</span>.<span class="pl-s1">_path</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>(<span class="pl-s1">v1</span>,<span class="pl-s1">c1</span>)       <span class="pl-c"># Changing the number of vertices like the </span>
                                           <span class="pl-c"># original code doesn't seem to work. </span>
                                           <span class="pl-c"># Must create new path.</span>

        <span class="pl-k">else</span>:
            <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">'unable to set bounds for spine "%s"'</span> <span class="pl-c1">%</span>
                             <span class="pl-s1">self</span>.<span class="pl-s1">spine_type</span>)


    <span class="pl-en">@<span class="pl-s1">classmethod</span></span>
    <span class="pl-k">def</span> <span class="pl-en">linear_spine</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">axes</span>, <span class="pl-s1">spine_type</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):
        <span class="pl-s">"""</span>
<span class="pl-s">        (staticmethod) Returns a linear :class:`Spine`.</span>
<span class="pl-s">        """</span>
        <span class="pl-s1">breaks</span> <span class="pl-c1">=</span> <span class="pl-s1">kwargs</span>.<span class="pl-en">pop</span>(<span class="pl-s">'breaks'</span>)
        <span class="pl-c"># all values of 0.999 get replaced upon call to set_bounds()</span>
        <span class="pl-k">if</span> <span class="pl-s1">spine_type</span> <span class="pl-c1">==</span> <span class="pl-s">'left'</span>:
            <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>([(<span class="pl-c1">0.0</span>, <span class="pl-c1">0.999</span>), (<span class="pl-c1">0.0</span>, <span class="pl-c1">0.999</span>)])
        <span class="pl-k">elif</span> <span class="pl-s1">spine_type</span> <span class="pl-c1">==</span> <span class="pl-s">'right'</span>:
            <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>([(<span class="pl-c1">1.0</span>, <span class="pl-c1">0.999</span>), (<span class="pl-c1">1.0</span>, <span class="pl-c1">0.999</span>)])
        <span class="pl-k">elif</span> <span class="pl-s1">spine_type</span> <span class="pl-c1">==</span> <span class="pl-s">'top'</span>:
            <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>([(<span class="pl-c1">0.999</span>, <span class="pl-c1">1.0</span>), (<span class="pl-c1">0.999</span>, <span class="pl-c1">1.0</span>)])
        <span class="pl-k">elif</span> <span class="pl-s1">spine_type</span> <span class="pl-c1">==</span> <span class="pl-s">'bottom'</span>:
            <span class="pl-s1">verts</span> <span class="pl-c1">=</span> []
            <span class="pl-s1">codes</span> <span class="pl-c1">=</span> []
            <span class="pl-s1">low</span>, <span class="pl-s1">high</span> <span class="pl-c1">=</span> <span class="pl-s1">axes</span>.<span class="pl-s1">viewLim</span>.<span class="pl-s1">intervalx</span>
            <span class="pl-s1">codes</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">MOVETO</span>)
            <span class="pl-s1">verts</span>.<span class="pl-en">append</span>([<span class="pl-s1">low</span>, <span class="pl-c1">0.0</span>])
            <span class="pl-k">for</span> (<span class="pl-s1">lower</span>, <span class="pl-s1">upper</span>) <span class="pl-c1">in</span> <span class="pl-s1">breaks</span>:
                <span class="pl-s1">codes</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">LINETO</span>)
                <span class="pl-s1">verts</span>.<span class="pl-en">append</span>([<span class="pl-s1">lower</span>, <span class="pl-c1">0.0</span>])
                <span class="pl-s1">codes</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">MOVETO</span>)
                <span class="pl-s1">verts</span>.<span class="pl-en">append</span>([<span class="pl-s1">upper</span>, <span class="pl-c1">0.0</span>]) 
            <span class="pl-s1">codes</span>.<span class="pl-en">append</span>(<span class="pl-v">Path</span>.<span class="pl-v">LINETO</span>)
            <span class="pl-s1">verts</span>.<span class="pl-en">append</span>([<span class="pl-s1">high</span>, <span class="pl-c1">0.0</span>])

            <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>(<span class="pl-s1">verts</span>,<span class="pl-s1">codes</span>) 
            <span class="pl-en">print</span>(<span class="pl-s1">path</span>)

        <span class="pl-k">else</span>:
            <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">'unable to make path for spine "%s"'</span> <span class="pl-c1">%</span> <span class="pl-s1">spine_type</span>)
            
        <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-en">cls</span>(<span class="pl-s1">axes</span>, <span class="pl-s1">spine_type</span>, <span class="pl-s1">path</span>, <span class="pl-s1">breaks</span><span class="pl-c1">=</span><span class="pl-s1">breaks</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
        <span class="pl-s1">result</span>.<span class="pl-en">set_visible</span>(<span class="pl-s1">rcParams</span>[<span class="pl-s">'axes.spines.{0}'</span>.<span class="pl-en">format</span>(<span class="pl-s1">spine_type</span>)])

        <span class="pl-k">return</span> <span class="pl-s1">result</span></pre></div>
<p dir="auto"><strong>Example</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="mscale.register_scale(BrokenScale)

plt.figure()
x = np.concatenate((np.linspace(0,2*np.pi,100), np.linspace(10*np.pi,12*np.pi,100)))
y = np.sin(x)
plt.plot(x, y,'.')
plt.xscale('broken', breaks=[[2*np.pi, 10*np.pi]])
plt.show()
ax = plt.gca()
ax.spines['bottom'] = BrokenSpine.linear_spine(ax, 'bottom', breaks=[[2*np.pi, 10*np.pi]])"><pre class="notranslate"><span class="pl-s1">mscale</span>.<span class="pl-en">register_scale</span>(<span class="pl-v">BrokenScale</span>)

<span class="pl-s1">plt</span>.<span class="pl-en">figure</span>()
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">concatenate</span>((<span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">0</span>,<span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>,<span class="pl-c1">100</span>), <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">10</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>,<span class="pl-c1">12</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>,<span class="pl-c1">100</span>)))
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">sin</span>(<span class="pl-s1">x</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>,<span class="pl-s">'.'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">xscale</span>(<span class="pl-s">'broken'</span>, <span class="pl-s1">breaks</span><span class="pl-c1">=</span>[[<span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>, <span class="pl-c1">10</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>]])
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">gca</span>()
<span class="pl-s1">ax</span>.<span class="pl-s1">spines</span>[<span class="pl-s">'bottom'</span>] <span class="pl-c1">=</span> <span class="pl-v">BrokenSpine</span>.<span class="pl-en">linear_spine</span>(<span class="pl-s1">ax</span>, <span class="pl-s">'bottom'</span>, <span class="pl-s1">breaks</span><span class="pl-c1">=</span>[[<span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>, <span class="pl-c1">10</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>]])</pre></div>