Python matplotlib.pyplot: How to make a histogram with bins counts including right bin edge?
<p>could you please help me, how to modify the code so to get a histogram with bins counts including right bin edge i.e.  <code>bins[i-1] &lt; x &lt;= bins[i]</code> (and no the Left as by default) ? </p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np
data = [0,1,2,3,4]
binwidth = 1
plt.hist(data, bins=np.arange(min(data), max(data) + binwidth, binwidth))
plt.xlabel('Time')
plt.ylabel('Counts')
plt.show()
</code></pre>

<p>Thank you in advance.</p>

<p>I do not think there is an option to do it explicitly in either matplotlib or numpy.</p>

<p>However, you may use <code>np.histogram()</code> with negative value of your <code>data</code> (and bins), then negate the output and plot it with <code>plt.bar()</code> function.</p>

<pre><code>bins = np.arange(min(data), max(data) + binwidth, binwidth)
hist, binsHist = np.histogram(-data, bins=sorted(-bins))
plt.plot(-binsHist[1:], -hist, np.diff(binHist))
</code></pre>

python matplotlib histogram