My data consists of a variety of volatility values, that is, decimal numbers between 0 and 1. Now, only values between 6% and 24% are particularly relevant and so I'm trying to build a histogram to show the relative counts of these values. I want a histogram that has bins of 0-6%, 6-8%, ... 22-24%, >24% but this proving to be very difficult. There should be 11 bins total, and the labels for the bins should be centered under the bins. The y-axis can't have any labels as only the relative counts matter, and including values on the y-axis would detract from the relativity that I'm trying to emphasize.
I have come crazy close to being able to do this by reading answers like Matplotlib xticks not lining up with histogram and Bin size in Matplotlib (Histogram).
If anyone can help me out with this, I would be immensely grateful. Thanks for your help out there.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.path as path
graph1, ax = plt.subplots()
n, bins = np.histogram(values, 11)
left = np.array(bins[:-1])
right = np.array(bins[1:])
bottom = np.zeros(len(left))
top = bottom + n
XY = np.array([[left, left, right, right], [bottom, top, top, bottom]]).T
barpath = path.Path.make_compound_path_from_polys(XY)
patch = patches.PathPatch(barpath, facecolor="blue", edgecolor="#FFFFFF",
alpha = 0.75)
ax.add_patch(patch)
ax.set_xlim(left[0], right[-1])
ax.set_ylim(bottom.min(), top.max())
graph1.suptitle("1-Year Rolling Volatilities")
ax.axes.get_yaxis().set_visible(False)
plt.show()
This generates almost the right histogram, but the bins aren't on the intervals that I want, the xticks aren't centered, and there isn't one label for each bin.