<p dir="auto">matplotlib's <code class="notranslate">pyplot.hist</code> and <code class="notranslate">pyplot.hist2d</code> functions fill the supplied data into histogram bins and plot them, but very often users will have already done the first step (sorting data into bins) in their own code and are merely interested in presenting their results in a "style" that is evocative of histograms (most commonly: bar chart with no separation for 1D data, colored grid for 2D data).</p>
<p dir="auto">Right now they can do this by using the <code class="notranslate">pyplot.bar</code> and <code class="notranslate">pyplot.imshow</code> functions for 1D and 2D data, respectively, but they have to fill in a bunch of arguments to make it look like something produced by <code class="notranslate">pyplot.hist</code> or <code class="notranslate">pyplot.hist2d</code> and they have to find out that those two are the right functions for the job in the first place (not very intuitive).</p>
<p dir="auto">Hence I think it would be good if there were separate functions or maybe just special arguments to <code class="notranslate">pyplot.hist/hist2d</code> that allow you to plot bin <em>values</em> (as opposed to data that is yet to be binned) as histograms that look exactly as if they had been produced by <code class="notranslate">pyplot.hist/hist2d</code>.</p>
<p dir="auto">The following script and the image it produces illustrates the issue:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
import numpy as np

from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

fig, ax = plt.subplots()

imax = ax.imshow(np.random.random((200, 200)), extent=[0, 100, 0, 1], aspect=100)

divider = make_axes_locatable(ax)

cax = divider.append_axes(&quot;right&quot;, size=&quot;5%&quot;, pad=&quot;2%&quot;)

cb = fig.colorbar(imax, cax=cax)"><pre class="notranslate"><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">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">mpl_toolkits</span>.<span class="pl-s1">axes_grid1</span> <span class="pl-k">import</span> <span class="pl-s1">make_axes_locatable</span>

<span class="pl-s1">fig</span>, <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>()

<span class="pl-s1">imax</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">imshow</span>(<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>((<span class="pl-c1">200</span>, <span class="pl-c1">200</span>)), <span class="pl-s1">extent</span><span class="pl-c1">=</span>[<span class="pl-c1">0</span>, <span class="pl-c1">100</span>, <span class="pl-c1">0</span>, <span class="pl-c1">1</span>], <span class="pl-s1">aspect</span><span class="pl-c1">=</span><span class="pl-c1">100</span>)

<span class="pl-s1">divider</span> <span class="pl-c1">=</span> <span class="pl-en">make_axes_locatable</span>(<span class="pl-s1">ax</span>)

<span class="pl-s1">cax</span> <span class="pl-c1">=</span> <span class="pl-s1">divider</span>.<span class="pl-en">append_axes</span>(<span class="pl-s">"right"</span>, <span class="pl-s1">size</span><span class="pl-c1">=</span><span class="pl-s">"5%"</span>, <span class="pl-s1">pad</span><span class="pl-c1">=</span><span class="pl-s">"2%"</span>)

<span class="pl-s1">cb</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">imax</span>, <span class="pl-s1">cax</span><span class="pl-c1">=</span><span class="pl-s1">cax</span>)</pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/3126246/6853080/fcb2b234-d3a5-11e4-8d3a-e346b43279c1.png"><img src="https://cloud.githubusercontent.com/assets/3126246/6853080/fcb2b234-d3a5-11e4-8d3a-e346b43279c1.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">As a workaround, I can produce the plot I'm looking for using ImageGrid:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
import numpy as np

from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid

fig = plt.figure(1, (8, 4))

grid = ImageGrid(fig, 111, nrows_ncols = (1, 1), axes_pad=0.1, cbar_mode='single')

imax = grid[0].imshow(np.random.random((200, 200)), extent=[0, 100, 0, 1], aspect=100)

cax = grid.cbar_axes[0]

cb = fig.colorbar(imax, cax=cax)"><pre class="notranslate"><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">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">mpl_toolkits</span>.<span class="pl-s1">axes_grid1</span> <span class="pl-k">import</span> <span class="pl-v">ImageGrid</span>

<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-c1">1</span>, (<span class="pl-c1">8</span>, <span class="pl-c1">4</span>))

<span class="pl-s1">grid</span> <span class="pl-c1">=</span> <span class="pl-v">ImageGrid</span>(<span class="pl-s1">fig</span>, <span class="pl-c1">111</span>, <span class="pl-s1">nrows_ncols</span> <span class="pl-c1">=</span> (<span class="pl-c1">1</span>, <span class="pl-c1">1</span>), <span class="pl-s1">axes_pad</span><span class="pl-c1">=</span><span class="pl-c1">0.1</span>, <span class="pl-s1">cbar_mode</span><span class="pl-c1">=</span><span class="pl-s">'single'</span>)

<span class="pl-s1">imax</span> <span class="pl-c1">=</span> <span class="pl-s1">grid</span>[<span class="pl-c1">0</span>].<span class="pl-en">imshow</span>(<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random</span>((<span class="pl-c1">200</span>, <span class="pl-c1">200</span>)), <span class="pl-s1">extent</span><span class="pl-c1">=</span>[<span class="pl-c1">0</span>, <span class="pl-c1">100</span>, <span class="pl-c1">0</span>, <span class="pl-c1">1</span>], <span class="pl-s1">aspect</span><span class="pl-c1">=</span><span class="pl-c1">100</span>)

<span class="pl-s1">cax</span> <span class="pl-c1">=</span> <span class="pl-s1">grid</span>.<span class="pl-s1">cbar_axes</span>[<span class="pl-c1">0</span>]

<span class="pl-s1">cb</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">colorbar</span>(<span class="pl-s1">imax</span>, <span class="pl-s1">cax</span><span class="pl-c1">=</span><span class="pl-s1">cax</span>)</pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/3126246/6853141/8ffc19f4-d3a6-11e4-8f08-1bc449717658.png"><img src="https://cloud.githubusercontent.com/assets/3126246/6853141/8ffc19f4-d3a6-11e4-8f08-1bc449717658.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">I think this might be related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="38425734" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/3286" data-hovercard-type="issue" data-hovercard-url="/matplotlib/matplotlib/issues/3286/hovercard" href="https://github.com/matplotlib/matplotlib/issues/3286">#3286</a>.  Not sure if it's an out and out duplicate or just another symptom of the same basic issue with <code class="notranslate">make_axes_locatable</code>.</p>
<p dir="auto">Some version info:</p>
<p dir="auto">numpy 1.9.2<br>
matplotlib 1.4.3<br>
python 2.7.9</p>