Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
c38efa07
Commit
c38efa07
authored
9 years ago
by
Guillaume Valadon
Browse files
Options
Downloads
Patches
Plain Diff
Adapting multiplot() to work with matplotlib
parent
69eb6679
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/plist.py
+22
-10
22 additions, 10 deletions
scapy/plist.py
with
22 additions
and
10 deletions
scapy/plist.py
+
22
−
10
View file @
c38efa07
...
@@ -191,22 +191,34 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
...
@@ -191,22 +191,34 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
return
lines
return
lines
def
multiplot
(
self
,
f
,
lfilter
=
None
,
**
kargs
):
def
multiplot
(
self
,
f
,
lfilter
=
None
,
**
kargs
):
"""
Uses a function that returns a label and a value for this label, then plots all the values label by label
"""
"""
Uses a function that returns a label and a value for this label, then
plots all the values label by label.
A list of matplotlib.lines.Line2D is returned.
"""
# Get the list of packets
l
=
self
.
res
l
=
self
.
res
# Apply the filter
if
lfilter
is
not
None
:
if
lfilter
is
not
None
:
l
=
filter
(
lfilter
,
l
)
l
=
filter
(
lfilter
,
l
)
d
=
{}
# Apply the function f to the packets
for
e
in
l
:
d_x
=
{}
k
,
v
=
f
(
e
)
d_y
=
{}
if
k
in
d
:
for
k
,
v
in
map
(
f
,
l
):
d
[
k
].
append
(
v
)
x
,
y
=
v
else
:
d_x
[
k
]
=
d_x
.
get
(
k
,
[])
+
[
x
]
d
[
k
]
=
[
v
]
d_y
[
k
]
=
d_y
.
get
(
k
,
[])
+
[
y
]
# Mimic the default gnuplot output
if
kargs
==
{}:
kargs
=
MATPLOTLIB_DEFAULT_PLOT_KARGS
lines
=
[]
lines
=
[]
for
k
in
d
:
for
k
in
d
_x
:
lines
+=
plt
.
plot
(
d
[
k
],
label
=
k
,
**
kargs
)
lines
+=
plt
.
plot
(
d
_x
[
k
],
d_y
[
k
],
label
=
k
,
**
kargs
)
plt
.
legend
(
loc
=
"
center right
"
,
bbox_to_anchor
=
(
1.5
,
0.5
))
plt
.
legend
(
loc
=
"
center right
"
,
bbox_to_anchor
=
(
1.5
,
0.5
))
# Call show() if matplotlib is not inlined
# Call show() if matplotlib is not inlined
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment