Skip to content
Snippets Groups Projects
Commit c38efa07 authored by Guillaume Valadon's avatar Guillaume Valadon
Browse files

Adapting multiplot() to work with matplotlib

parent 69eb6679
No related branches found
No related tags found
No related merge requests found
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment