2 import matplotlib
.pyplot
as plt
5 components
= [ 'Sensor Interface',
13 plt
.rcParams
["font.family"] = "serif"
14 plt
.rcParams
['mathtext.fontset'] = 'custom'
15 plt
.rcParams
['mathtext.rm'] = 'Libertine'
16 plt
.rcParams
['mathtext.it'] = 'Libertine:italic'
17 plt
.rcParams
['mathtext.bf'] = 'Libertine:bold'
19 CB_color_cycle
= ['#377eb8', '#ff7f00', '#4daf4a',
20 '#f781bf', '#a65628', '#984ea3',
21 '#999999', '#e41a1c', '#dede00']
23 #data = '''PWS,PRS,CWS,CRS
30 data
= '''PWS,PRS,CWS,CRS
31 9.252669039145907,9.895833333333333,6.626506024096386,7.096774193548387
32 31.67259786476868,31.77083333333333,5.421686746987952,2.5806451612903226
33 13.523131672597866,13.194444444444445,21.084337349397592,19.35483870967742
34 9.9644128113879,9.722222222222222,16.86746987951807,18.064516129032257
35 18.861209964412812,18.40277777777778,46.987951807228917,50.32258064516129
36 16.725978647686832,17.01388888888889,3.0120481927710843,2.5806451612903226
39 # convert CSV literal string into pandas data frame
41 df
= pd
.read_csv(io
.StringIO(data
), sep
=",", header
=0)
45 fig
, ax
= plt
.subplots()
47 ax
.bar(df
.columns
, df
.loc
[components
[-1]], label
=components
[-1])
48 baseline
= df
.loc
[components
[-1]]
49 for i
in range(len(components
)-2, -1, -1):
50 ax
.bar(df
.columns
, df
.loc
[components
[i
]], label
=components
[i
],
51 bottom
= baseline
, color
=CB_color_cycle
[i
])
52 baseline
+= df
.loc
[components
[i
]]
55 for bar
in ax
.patches
:
57 # Put the text in the middle of each bar. get_x returns the start
58 # so we add half the width to get to the middle.
59 bar
.get_x() + bar
.get_width() / 2,
60 # Vertically, add the height of the bar to the start of the bar,
61 # along with the offset.
62 bar
.get_height() /2 + bar
.get_y() + y_offset
,
63 # bar.get_height() + bar.get_y() + y_offset,
64 # This is actual value we'll show.
65 round(bar
.get_height()),
66 # Center the labels and style them a bit.
73 #ax.bar(labels, women_means, width, yerr=women_std, bottom=men_means,
76 ax
.set_ylabel('% coverage')
77 #ax.set_title('Source code coverage by component')
79 box
= ax
.get_position()
80 ax
.set_position([box
.x0
, box
.y0
, box
.width
* 0.7, box
.height
])
82 handles
, labels
= plt
.gca().get_legend_handles_labels()
83 ##order = list(range(len(components)))
84 order
= list(range(len(components
)-1, -1, -1))
85 plt
.legend([handles
[idx
] for idx
in order
],[labels
[idx
] for idx
in order
], loc
='center left', bbox_to_anchor
=(1, 0.5))
89 plt
.savefig('bar_chart.pdf')