Created
April 7, 2022 21:57
-
-
Save jeremysinger/b76d93647a39a44e2f7ea4e9bfb3e21d to your computer and use it in GitHub Desktop.
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 characters
import io | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
components = [ 'Sensor Interface', | |
'Sensor Node', | |
'Manage Nodes', | |
'Web Interface', | |
'Database Interface', | |
'Communication' | |
] | |
data = '''PWS,PRS,CWS,CRS | |
9,10,7,7 | |
32,32,5,3 | |
14,13,21,19 | |
10,10,17,18 | |
19,18,47,50 | |
17,17,3,3''' | |
# convert CSV literal string into pandas data frame | |
df = pd.read_csv(io.StringIO(data), sep=",", header=0) | |
df.index = components | |
print(df) | |
fig, ax = plt.subplots() | |
ax.bar(df.columns, df.loc[components[-1]], label=components[-1]) | |
baseline = df.loc[components[-1]] | |
for i in range(len(components)-2, -1, -1): | |
ax.bar(df.columns, df.loc[components[i]], label=components[i], | |
bottom = baseline) | |
baseline += df.loc[components[i]] | |
#ax.bar(labels, women_means, width, yerr=women_std, bottom=men_means, | |
# label='Women') | |
ax.set_ylabel('% coverage') | |
ax.set_title('Source code coverage by component') | |
box = ax.get_position() | |
ax.set_position([box.x0, box.y0, box.width * 0.7, box.height]) | |
handles, labels = plt.gca().get_legend_handles_labels() | |
##order = list(range(len(components))) | |
order = list(range(len(components)-1, -1, -1)) | |
plt.legend([handles[idx] for idx in order],[labels[idx] for idx in order], loc='center left', bbox_to_anchor=(1, 0.5)) | |
##ax.legend() | |
plt.savefig('stacked_bar_chart.pdf') | |
##plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment