I am looking to create a stacked histogram but I cannot seem to get it to work correctly. To explain I have three pieces of data I wish to plot:
- Number of Hits (y-axis)
- Position of the hit in m (the histogram bin the hit falls in) (the x axis)
- The type of hit that falls into the bin from (2).
So far I have been able to create this:
This is generated using the following code:
pl.figure()
stats[ column ].plot( kind='hist', alpha=0.7, bins = 13 )
pl.xticks( np.linspace( 0, 0.013, num = 13, endpoint = False ), rotation=70 )
pl.axvline( 0.003, color='r', linestyle='dashed', linewidth=2)
pl.ylabel( "Number of Hits" )
pl.title( "Number of Hits " )
pl.savefig( output_file_name, bbox_inches='tight' )
print( "Saved Figure to ", output_file_name )
What I want to do is to have the values so that each bin is stacked. I have three types of hits that can occur. I would like to call them Hit1, Hit2, Hit3. They are all stored in a Pandas dataframe which has the following structure:
df = # | value | hit type | location
----------------------------------------
(int) | float(64) | string | float(64)
The column under the title value is not relevant other than it is part of the original pandas dataframe.
The problem I am running into is that I am unable to stack these varying data types. I can already plot the number of times a hit falls into a specific location (bin in the histogram) but I am unable to do this in a manner that leads to having three colors in the plot one for each "type" of hit that is found.