Created
May 22, 2016 23:46
Revisions
-
arbennett created this gist
May 22, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ """ Script to do multiple stacked bar subplots """ import matplotlib.pyplot as plt data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] colors=['r','g','b','y'] n_bars = len(data) fig, ax = plt.subplots(1,n_bars) # Go through each separate bar subplot for bar in range(n_bars): n_segments = len(data[bar]) segment_data = data[bar] offset = 0 # Create the subplot for segment in range(n_segments): # Select the new subplot plt.subplot(1,n_bars, bar) plt.bar(1, segment_data[segment], bottom=offset, color=colors[segment]) # Extend offset by current data amount so that stacking works properly offset += segment_data[segment] plt.show()