I want to plot a histogram of financial data. Specifically, I want to plot a histogram of index returns, where the return is on the x axes and the number count on the y-axes.
I used the following Code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
returns = (0.08,0.05,-0.15,0.12,-0.18,0.02,0.25)
years = (2010,2011,2012,2013,2014,2015,2016)
data = pd.DataFrame(returns, columns = ["Return"], index = years)
bins = [-0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4, 0.5]
plt.hist(data, bins = bins, edgecolor = "white")
This codes yields the following plot. When I now look at the data for returns between -20% and - 10% there are 2 years that fall within this range (2012 and 2014). What I want to do now is basically that the bin that is containing these 2 observations between -20% and -10% is seperated into 2 bins which are stacked on top of each other but that the year of the observation is displayed inside the bins. So that I can see the two corresponding years for the bin when lookin at the plot. But I cannot find any hint how to do that in the documentation.