Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
X-Lap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
LARN
X-Lap
Commits
87ed00ce
Commit
87ed00ce
authored
Feb 14, 2018
by
Andreas Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move labels to bars in vertical graph.
parent
fbf30046
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
5 deletions
+36
-5
xlap/analyse/latency.py
xlap/analyse/latency.py
+36
-5
No files found.
xlap/analyse/latency.py
View file @
87ed00ce
...
...
@@ -116,6 +116,33 @@ def _plot_controlflow_graph(df, hdb):
# print("\t_node__"+edge['Start'] + " -> _node__"+edge['End'] + "[label=\""+str(edge['Correlation'])+"\"];")
print
(
"}"
)
# Taken from: http://composition.al/blog/2015/11/29/a-better-way-to-add-labels-to-bar-charts-with-matplotlib/
def
autolabel
(
rects
,
ax
,
labels
):
# Get y-axis height to calculate label position from.
(
y_bottom
,
y_top
)
=
ax
.
get_ylim
()
y_height
=
y_top
-
y_bottom
for
i
,
rect
in
enumerate
(
rects
):
height
=
rect
.
get_height
()
color
=
"black"
# Fraction of axis height taken up by this rectangle
p_height
=
(
height
/
y_height
)
# If we can fit the label above the column, do that;
# otherwise, put it inside the column.
if
p_height
>
0.50
:
# arbitrary; 95% looked good to me.
label_position
=
0.01
color
=
"white"
else
:
label_position
=
height
+
(
y_height
*
0.01
)
ax
.
text
(
rect
.
get_x
()
+
rect
.
get_width
()
/
2.
,
label_position
,
labels
[
i
],
ha
=
'center'
,
va
=
'bottom'
,
rotation
=
90
,
color
=
color
)
def
_plot_critical_regions
(
df
,
hdb
):
"""
plot regions, sorted by latency criticality
...
...
@@ -123,18 +150,22 @@ def _plot_critical_regions(df,hdb):
for
region
in
sorted
(
hdb
,
key
=
lambda
x
:
-
x
[
'Correlation'
]):
print
(
"%-10f %10s -> %10s"
%
(
region
[
'Correlation'
],
region
[
'Start'
],
region
[
'End'
]),
file
=
sys
.
stderr
)
relevant
=
sorted
([
x
for
x
in
hdb
if
x
[
'Correlation'
]
>
0
],
key
=
lambda
x
:
-
x
[
'Correlation'
])
relevant
=
sorted
([
x
for
x
in
hdb
if
x
[
'Correlation'
]
>
0
],
key
=
lambda
x
:
-
x
[
'Correlation'
]
,
reverse
=
True
)
x
=
np
.
arange
(
len
(
relevant
))
bars
=
plt
.
bar
(
x
,
list
(
map
(
lambda
x
:
x
[
'Correlation'
],
relevant
)))
correlations
=
list
(
map
(
lambda
x
:
x
[
'Correlation'
],
relevant
))
ticks
=
list
(
map
(
lambda
x
:
"%s-%s"
%
(
x
[
'Start'
][:
-
2
],
x
[
'End'
][:
-
2
]),
relevant
))
fig
,
ax
=
plt
.
subplots
()
rects
=
ax
.
bar
(
x
,
correlations
,
align
=
"center"
,
tick_label
=
""
)
autolabel
(
rects
,
ax
,
ticks
)
# TODO: find a more elegant solution for the label text
plt
.
xticks
(
x
,
list
(
map
(
lambda
x
:
"%s-%s"
%
(
x
[
'Start'
][:
-
2
],
x
[
'End'
][:
-
2
])
,
relevant
)),
rotation
=
90
)
plt
.
tight_layout
()
plt
.
savefig
(
"latency-criticality.p
ng
"
)
plt
.
savefig
(
"latency-criticality.p
df
"
)
plt
.
close
()
def
analyse
(
df
,
config
):
hb
=
[]
for
event1
in
df
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment