Created
November 21, 2019 12:53
-
-
Save macleginn/3924c973dbd74e8e9b320447b92aee4a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# test.csv: | |
# ,b,c,d | |
# p,1,2,3 | |
# q,4,5,6 | |
# r,7,8,9 | |
df = pd.read_csv('test.csv', index_col=0) | |
N = df.shape[1] | |
fig = plt.figure(figsize=(16,10)) | |
ind = np.arange(N) | |
layers = [] | |
for i in range(df.shape[0]): | |
if i == 0: | |
layers.append(plt.bar(ind, df.iloc[i,:])) | |
else: | |
layers.append(plt.bar(ind, df.iloc[i,:], bottom=df.iloc[i-1,:])) | |
plt.legend(layers, list(df.columns)) | |
plt.xticks(ind, list(df.index)) | |
fig.savefig('stackedbar.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment