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.
(self,
f, # type: Callable[..., Any]
lfilter=None, # type: Optional[Callable[..., Any]]
plot_xy=False, # type: bool
**kargs # type: Any
)
| 344 | return lines |
| 345 | |
| 346 | def multiplot(self, |
| 347 | f, # type: Callable[..., Any] |
| 348 | lfilter=None, # type: Optional[Callable[..., Any]] |
| 349 | plot_xy=False, # type: bool |
| 350 | **kargs # type: Any |
| 351 | ): |
| 352 | # type: (...) -> Line2D |
| 353 | """Uses a function that returns a label and a value for this label, then |
| 354 | plots all the values label by label. |
| 355 | |
| 356 | A list of matplotlib.lines.Line2D is returned. |
| 357 | """ |
| 358 | # Defer imports of matplotlib until its needed |
| 359 | # because it has a heavy dep chain |
| 360 | from scapy.libs.matplot import ( |
| 361 | plt, |
| 362 | MATPLOTLIB_INLINED, |
| 363 | MATPLOTLIB_DEFAULT_PLOT_KARGS |
| 364 | ) |
| 365 | |
| 366 | # Get the list of packets |
| 367 | if lfilter is None: |
| 368 | lst_pkts = (f(*e) for e in self.res) |
| 369 | else: |
| 370 | lst_pkts = (f(*e) for e in self.res if lfilter(*e)) |
| 371 | |
| 372 | # Apply the function f to the packets |
| 373 | d = {} # type: Dict[str, List[float]] |
| 374 | for k, v in lst_pkts: |
| 375 | d.setdefault(k, []).append(v) |
| 376 | |
| 377 | # Mimic the default gnuplot output |
| 378 | if not kargs: |
| 379 | kargs = MATPLOTLIB_DEFAULT_PLOT_KARGS |
| 380 | |
| 381 | if plot_xy: |
| 382 | lines = [plt.plot(*list(zip(*pl)), **dict(kargs, label=k)) |
| 383 | for k, pl in d.items()] |
| 384 | else: |
| 385 | lines = [plt.plot(pl, **dict(kargs, label=k)) |
| 386 | for k, pl in d.items()] |
| 387 | plt.legend(loc="center right", bbox_to_anchor=(1.5, 0.5)) |
| 388 | |
| 389 | # Call show() if matplotlib is not inlined |
| 390 | if not MATPLOTLIB_INLINED: |
| 391 | plt.show() |
| 392 | |
| 393 | return lines |
| 394 | |
| 395 | def rawhexdump(self): |
| 396 | # type: () -> None |