<p dir="auto">The weekly build with nightly wheels from numpy and pandas<br>
has failed. Check the logs for any updates that need to be<br>
made in matplotlib.<br>
<a href="https://github.com/matplotlib/matplotlib/actions/runs/4900029117">https://github.com/matplotlib/matplotlib/actions/runs/4900029117</a></p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">When specifying hatches for <code class="notranslate">contourf,</code> the colorbar is drawn correctly for vertical colorbars but not for horizontal ones. The Hatches and colorfill only fill the lower diagonal of the colorbar boxes.</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.pyplot as plt
import numpy as np

import matplotlib.pyplot as plt
import numpy as np

# invent some numbers, turning the x and y arrays into simple
# 2d arrays, which make combining them together easier.
x = np.linspace(-3, 5, 150).reshape(1, -1)
y = np.linspace(-3, 5, 120).reshape(-1, 1)
z = np.cos(x) + np.sin(y)

# we no longer need x and y to be 2 dimensional, so flatten them.
x, y = x.flatten(), y.flatten()

fig1, ax1 = plt.subplots()
cs = ax1.contourf(x, y, z, hatches=['-', '/', '\\', '//'],
                  cmap='gray', extend='both', alpha=0.5)

fig1.colorbar(cs, orientation='horizontal')
plt.show()"><pre class="notranslate"><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-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">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-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-c"># invent some numbers, turning the x and y arrays into simple</span>
<span class="pl-c"># 2d arrays, which make combining them together easier.</span>
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">-</span><span class="pl-c1">3</span>, <span class="pl-c1">5</span>, <span class="pl-c1">150</span>).<span class="pl-en">reshape</span>(<span class="pl-c1">1</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>)
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">-</span><span class="pl-c1">3</span>, <span class="pl-c1">5</span>, <span class="pl-c1">120</span>).<span class="pl-en">reshape</span>(<span class="pl-c1">-</span><span class="pl-c1">1</span>, <span class="pl-c1">1</span>)
<span class="pl-s1">z</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">cos</span>(<span class="pl-s1">x</span>) <span class="pl-c1">+</span> <span class="pl-s1">np</span>.<span class="pl-en">sin</span>(<span class="pl-s1">y</span>)

<span class="pl-c"># we no longer need x and y to be 2 dimensional, so flatten them.</span>
<span class="pl-s1">x</span>, <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">x</span>.<span class="pl-en">flatten</span>(), <span class="pl-s1">y</span>.<span class="pl-en">flatten</span>()

<span class="pl-s1">fig1</span>, <span class="pl-s1">ax1</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>()
<span class="pl-s1">cs</span> <span class="pl-c1">=</span> <span class="pl-s1">ax1</span>.<span class="pl-en">contourf</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>, <span class="pl-s1">z</span>, <span class="pl-s1">hatches</span><span class="pl-c1">=</span>[<span class="pl-s">'-'</span>, <span class="pl-s">'/'</span>, <span class="pl-s">'<span class="pl-cce">\\</span>'</span>, <span class="pl-s">'//'</span>],
                  <span class="pl-s1">cmap</span><span class="pl-c1">=</span><span class="pl-s">'gray'</span>, <span class="pl-s1">extend</span><span class="pl-c1">=</span><span class="pl-s">'both'</span>, <span class="pl-s1">alpha</span><span class="pl-c1">=</span><span class="pl-c1">0.5</span>)

<span class="pl-s1">fig1</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">cs</span>, <span class="pl-s1">orientation</span><span class="pl-c1">=</span><span class="pl-s">'horizontal'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/42781301/180038311-1100fca9-bbaa-4baa-93fb-97ccc56d8260.png"><img src="https://user-images.githubusercontent.com/42781301/180038311-1100fca9-bbaa-4baa-93fb-97ccc56d8260.png" alt="actual_colobar" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/42781301/180038758-eb0177ff-52c8-49cf-9fd4-d927fc4170b6.png"><img src="https://user-images.githubusercontent.com/42781301/180038758-eb0177ff-52c8-49cf-9fd4-d927fc4170b6.png" alt="expected_colorbar" style="max-width: 100%;"></a></p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">The bug occurs when the colorbar is horizontal and the <code class="notranslate">contourf</code> call uses hatches. Changing the kwargs <code class="notranslate">extend</code>, <code class="notranslate">cmap</code>, <code class="notranslate">colors</code>, <code class="notranslate">alpha</code>, etc when calling <code class="notranslate">contourf</code> does <em>not</em> resolve the bug.</p>
<p dir="auto">The bug does <em>not</em> occur when the colorbar is vertical with hatches nor when the colorbar is horizontal and no hatches are used.</p>
<p dir="auto"><em>Potential Solution</em>:<br>
In colorbar.py, change line 637 to the following:<br>
<code class="notranslate">xy = np.array([[X[i, 0], Y[i, 1]],</code></p>
<p dir="auto">This doesn't cause issues when hatches are not used. It also doesn't cause problems with vertical colorbars.</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">macOS Big Sur Version 11.3.1 with Intel Silicon</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.2</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">module://backend_interagg</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.10.5</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto">conda</p>