<p dir="auto">I have been using the fill_between function before and recently I have started receiving an <code class="notranslate">IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed</code> . I also tried some examples using the fill_between function in your documentation (<a href="https://matplotlib.org/stable/gallery/lines_bars_and_markers/fill_between_alpha.html#sphx-glr-gallery-lines-bars-and-markers-fill-between-alpha-py" rel="nofollow">https://matplotlib.org/stable/gallery/lines_bars_and_markers/fill_between_alpha.html#sphx-glr-gallery-lines-bars-and-markers-fill-between-alpha-py</a>) and was receiving the same error each time. I am currently using matplotlib version 3.5.1 and python version 3.10.6</p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">There is a test in <code class="notranslate">astropy</code> that started breaking when using matplotlib + numpy 1.24.0.dev0+896.g5ecaf36cd . Same error using stable matplotlib and matplotlib from the nightly wheel.</p>
<p dir="auto">The actual test is at <a href="https://github.com/astropy/astropy/blob/75f9b60b5521ed8dae08611ddf766c95ce421801/astropy/visualization/tests/test_units.py#L24">https://github.com/astropy/astropy/blob/75f9b60b5521ed8dae08611ddf766c95ce421801/astropy/visualization/tests/test_units.py#L24</a> but I will give reproducible example without astropy below.</p>
<p dir="auto">Example log with the astropy failure: <a href="https://github.com/astropy/astropy/actions/runs/3198205490/jobs/5222440278">https://github.com/astropy/astropy/actions/runs/3198205490/jobs/5222440278</a></p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('agg')
plt.figure()
plt.plot([1, 2, 3], [3, 4, 5], label='label')
plt.plot([1.05, 2.10, 3.15], [3.050, 3.025, 3.010])
plt.fill_between([1, 3], [3, 5], [3.050, 3.010])  # IndexError"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-s1">matplotlib</span>.<span class="pl-en">use</span>(<span class="pl-s">'agg'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">figure</span>()
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>], [<span class="pl-c1">3</span>, <span class="pl-c1">4</span>, <span class="pl-c1">5</span>], <span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'label'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>([<span class="pl-c1">1.05</span>, <span class="pl-c1">2.10</span>, <span class="pl-c1">3.15</span>], [<span class="pl-c1">3.050</span>, <span class="pl-c1">3.025</span>, <span class="pl-c1">3.010</span>])
<span class="pl-s1">plt</span>.<span class="pl-en">fill_between</span>([<span class="pl-c1">1</span>, <span class="pl-c1">3</span>], [<span class="pl-c1">3</span>, <span class="pl-c1">5</span>], [<span class="pl-c1">3.050</span>, <span class="pl-c1">3.010</span>])  <span class="pl-c"># IndexError</span></pre></div>
<h3 dir="auto">Actual outcome</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="File .../matplotlib/pyplot.py:2514, in fill_between(x, y1, y2, where, interpolate, step, data, **kwargs)
   2510 @_copy_docstring_and_deprecators(Axes.fill_between)
   2511 def fill_between(
   2512         x, y1, y2=0, where=None, interpolate=False, step=None, *,
   2513         data=None, **kwargs):
-&gt; 2514     return gca().fill_between(
   2515         x, y1, y2=y2, where=where, interpolate=interpolate, step=step,
   2516         **({&quot;data&quot;: data} if data is not None else {}), **kwargs)

File .../matplotlib/__init__.py:1423, in _preprocess_data.&lt;locals&gt;.inner(ax, data, *args, **kwargs)
   1420 @functools.wraps(func)
   1421 def inner(ax, *args, data=None, **kwargs):
   1422     if data is None:
-&gt; 1423         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1425     bound = new_sig.bind(ax, *args, **kwargs)
   1426     auto_label = (bound.arguments.get(label_namer)
   1427                   or bound.kwargs.get(label_namer))

File .../matplotlib/axes/_axes.py:5335, in Axes.fill_between(self, x, y1, y2, where, interpolate, step, **kwargs)
   5333 def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
   5334                  step=None, **kwargs):
-&gt; 5335     return self._fill_between_x_or_y(
   5336         &quot;x&quot;, x, y1, y2,
   5337         where=where, interpolate=interpolate, step=step, **kwargs)

File .../matplotlib/axes/_axes.py:5263, in Axes._fill_between_x_or_y(self, ind_dir, ind, dep1, dep2, where, interpolate, step, **kwargs)
   5259 ind, dep1, dep2 = np.broadcast_arrays(
   5260     np.atleast_1d(ind), dep1, dep2, subok=True)
   5262 polys = []
-&gt; 5263 for idx0, idx1 in cbook.contiguous_regions(where):
   5264     indslice = ind[idx0:idx1]
   5265     dep1slice = dep1[idx0:idx1]

File .../matplotlib/cbook/__init__.py:1333, in contiguous_regions(mask)
   1330     return []
   1332 # Find the indices of region changes, and correct offset
-&gt; 1333 idx, = np.nonzero(mask[:-1] != mask[1:])
   1334 idx += 1
   1336 # List operations are faster for moderately sized arrays

IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed"><pre class="notranslate"><code class="notranslate">File .../matplotlib/pyplot.py:2514, in fill_between(x, y1, y2, where, interpolate, step, data, **kwargs)
   2510 @_copy_docstring_and_deprecators(Axes.fill_between)
   2511 def fill_between(
   2512         x, y1, y2=0, where=None, interpolate=False, step=None, *,
   2513         data=None, **kwargs):
-&gt; 2514     return gca().fill_between(
   2515         x, y1, y2=y2, where=where, interpolate=interpolate, step=step,
   2516         **({"data": data} if data is not None else {}), **kwargs)

File .../matplotlib/__init__.py:1423, in _preprocess_data.&lt;locals&gt;.inner(ax, data, *args, **kwargs)
   1420 @functools.wraps(func)
   1421 def inner(ax, *args, data=None, **kwargs):
   1422     if data is None:
-&gt; 1423         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1425     bound = new_sig.bind(ax, *args, **kwargs)
   1426     auto_label = (bound.arguments.get(label_namer)
   1427                   or bound.kwargs.get(label_namer))

File .../matplotlib/axes/_axes.py:5335, in Axes.fill_between(self, x, y1, y2, where, interpolate, step, **kwargs)
   5333 def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
   5334                  step=None, **kwargs):
-&gt; 5335     return self._fill_between_x_or_y(
   5336         "x", x, y1, y2,
   5337         where=where, interpolate=interpolate, step=step, **kwargs)

File .../matplotlib/axes/_axes.py:5263, in Axes._fill_between_x_or_y(self, ind_dir, ind, dep1, dep2, where, interpolate, step, **kwargs)
   5259 ind, dep1, dep2 = np.broadcast_arrays(
   5260     np.atleast_1d(ind), dep1, dep2, subok=True)
   5262 polys = []
-&gt; 5263 for idx0, idx1 in cbook.contiguous_regions(where):
   5264     indslice = ind[idx0:idx1]
   5265     dep1slice = dep1[idx0:idx1]

File .../matplotlib/cbook/__init__.py:1333, in contiguous_regions(mask)
   1330     return []
   1332 # Find the indices of region changes, and correct offset
-&gt; 1333 idx, = np.nonzero(mask[:-1] != mask[1:])
   1334 idx += 1
   1336 # List operations are faster for moderately sized arrays

IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed
</code></pre></div>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">No error.</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">Only with numpy 1.24.0.dev0+896.g5ecaf36cd but not with stable numpy.</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Debian or Ubuntu</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">stable or nightly</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">agg</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.10 and 3.11</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto">N/A</p>
<h3 dir="auto">Installation</h3>
<p dir="auto">pip</p>