telemetry.gui.plotting

Docstring for telemetry.gui.plotting

This module contains functionality for generating graph plots from parsed event data.

This functionality is provided by the PlotTab class.

  1"""
  2Docstring for telemetry.gui.plotting
  3
  4This module contains functionality for generating graph plots from
  5parsed event data.
  6
  7This functionality is provided by the PlotTab class.
  8"""
  9
 10from tkinter import ttk
 11from matplotlib.figure import Figure
 12from matplotlib.ticker import FixedLocator
 13from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
 14
 15
 16class PlotTab:
 17    def __init__(
 18            self, 
 19            parent: ttk.Frame, 
 20            title: str, 
 21            xlabel: str = "", 
 22            ylabel: str = ""
 23    ):
 24        parent.rowconfigure(0, weight=1)
 25        parent.columnconfigure(0, weight=1)
 26
 27        container = ttk.Frame(parent)
 28        container.grid(row=0, column=0, sticky="nsew")
 29
 30        self.title = title
 31        self.xlabel = xlabel
 32        self.ylabel = ylabel
 33
 34        self.figure = Figure(figsize=(6, 4), dpi=90)
 35        self.axes = self.figure.add_subplot()
 36        self.axes.set_title(self.title)
 37        self.axes.set_xlabel(self.xlabel)
 38        self.axes.set_ylabel(self.ylabel)
 39
 40        self.canvas = FigureCanvasTkAgg(self.figure, master=container)
 41        self.canvas_widget = self.canvas.get_tk_widget()
 42        self.canvas_widget.pack(fill="both", expand=True)
 43
 44        self.color_map: dict[str, str] = {
 45            "Easy": "green",
 46            "Medium": "orange",
 47            "Hard": "red"
 48        }
 49
 50
 51    def plot_line(self, x, y, label=None):
 52        self.axes.clear()
 53        self.axes.set_title(self.title)
 54        self.axes.set_xlabel(self.xlabel)
 55        self.axes.set_ylabel(self.ylabel)
 56        stages = list(range(1, 11))
 57        self.axes.set_xlim(1, 10)
 58        self.axes.xaxis.set_major_locator(FixedLocator(stages))
 59
 60        self.axes.plot(
 61            x, 
 62            y, 
 63            linestyle=':', # dotted lines
 64            marker='o',    # dots on the points
 65            linewidth=3,   # thicker lines
 66            markersize=6,  # bolder points
 67            label=label, 
 68            color='black'
 69        )
 70        # self.axes.legend(
 71        #     handlelength=4,    # longer lines in legend
 72        #     markerscale=1,     # dot scale in legend
 73        #     handletextpad=0.2, # padding with text
 74        #     borderaxespad=0.2, # padding from border
 75        # )
 76
 77        self.axes.grid(True)
 78        self.canvas.draw()
 79
 80    def plot_multi_line(self, series: list[tuple[list, list, str]]):
 81        self.axes.clear()
 82        self.axes.set_title(self.title)
 83        self.axes.set_xlabel(self.xlabel)
 84        self.axes.set_ylabel(self.ylabel)
 85        stages = list(range(1, 11))
 86        self.axes.set_xlim(1, 10)
 87        self.axes.xaxis.set_major_locator(FixedLocator(stages))
 88
 89        for x, y, label in series:
 90            self.axes.plot(
 91                x, 
 92                y, 
 93                linestyle=':', # dotted lines
 94                marker='o',    # dots on the points
 95                linewidth=3,   # thicker lines
 96                markersize=6,  # bolder points
 97                label=label, 
 98                color=self.color_map[label] # map colour to difficulty
 99            )
100        self.axes.legend(
101            handlelength=0.5,    # longer line in legend
102            markerscale=1,     # dot scale in legend
103            handletextpad=0.4, # padding with text
104            borderaxespad=0.2, # padding from border
105        )
106        self.axes.grid(True)
107        self.canvas.draw()
class PlotTab:
 17class PlotTab:
 18    def __init__(
 19            self, 
 20            parent: ttk.Frame, 
 21            title: str, 
 22            xlabel: str = "", 
 23            ylabel: str = ""
 24    ):
 25        parent.rowconfigure(0, weight=1)
 26        parent.columnconfigure(0, weight=1)
 27
 28        container = ttk.Frame(parent)
 29        container.grid(row=0, column=0, sticky="nsew")
 30
 31        self.title = title
 32        self.xlabel = xlabel
 33        self.ylabel = ylabel
 34
 35        self.figure = Figure(figsize=(6, 4), dpi=90)
 36        self.axes = self.figure.add_subplot()
 37        self.axes.set_title(self.title)
 38        self.axes.set_xlabel(self.xlabel)
 39        self.axes.set_ylabel(self.ylabel)
 40
 41        self.canvas = FigureCanvasTkAgg(self.figure, master=container)
 42        self.canvas_widget = self.canvas.get_tk_widget()
 43        self.canvas_widget.pack(fill="both", expand=True)
 44
 45        self.color_map: dict[str, str] = {
 46            "Easy": "green",
 47            "Medium": "orange",
 48            "Hard": "red"
 49        }
 50
 51
 52    def plot_line(self, x, y, label=None):
 53        self.axes.clear()
 54        self.axes.set_title(self.title)
 55        self.axes.set_xlabel(self.xlabel)
 56        self.axes.set_ylabel(self.ylabel)
 57        stages = list(range(1, 11))
 58        self.axes.set_xlim(1, 10)
 59        self.axes.xaxis.set_major_locator(FixedLocator(stages))
 60
 61        self.axes.plot(
 62            x, 
 63            y, 
 64            linestyle=':', # dotted lines
 65            marker='o',    # dots on the points
 66            linewidth=3,   # thicker lines
 67            markersize=6,  # bolder points
 68            label=label, 
 69            color='black'
 70        )
 71        # self.axes.legend(
 72        #     handlelength=4,    # longer lines in legend
 73        #     markerscale=1,     # dot scale in legend
 74        #     handletextpad=0.2, # padding with text
 75        #     borderaxespad=0.2, # padding from border
 76        # )
 77
 78        self.axes.grid(True)
 79        self.canvas.draw()
 80
 81    def plot_multi_line(self, series: list[tuple[list, list, str]]):
 82        self.axes.clear()
 83        self.axes.set_title(self.title)
 84        self.axes.set_xlabel(self.xlabel)
 85        self.axes.set_ylabel(self.ylabel)
 86        stages = list(range(1, 11))
 87        self.axes.set_xlim(1, 10)
 88        self.axes.xaxis.set_major_locator(FixedLocator(stages))
 89
 90        for x, y, label in series:
 91            self.axes.plot(
 92                x, 
 93                y, 
 94                linestyle=':', # dotted lines
 95                marker='o',    # dots on the points
 96                linewidth=3,   # thicker lines
 97                markersize=6,  # bolder points
 98                label=label, 
 99                color=self.color_map[label] # map colour to difficulty
100            )
101        self.axes.legend(
102            handlelength=0.5,    # longer line in legend
103            markerscale=1,     # dot scale in legend
104            handletextpad=0.4, # padding with text
105            borderaxespad=0.2, # padding from border
106        )
107        self.axes.grid(True)
108        self.canvas.draw()
PlotTab( parent: tkinter.ttk.Frame, title: str, xlabel: str = '', ylabel: str = '')
18    def __init__(
19            self, 
20            parent: ttk.Frame, 
21            title: str, 
22            xlabel: str = "", 
23            ylabel: str = ""
24    ):
25        parent.rowconfigure(0, weight=1)
26        parent.columnconfigure(0, weight=1)
27
28        container = ttk.Frame(parent)
29        container.grid(row=0, column=0, sticky="nsew")
30
31        self.title = title
32        self.xlabel = xlabel
33        self.ylabel = ylabel
34
35        self.figure = Figure(figsize=(6, 4), dpi=90)
36        self.axes = self.figure.add_subplot()
37        self.axes.set_title(self.title)
38        self.axes.set_xlabel(self.xlabel)
39        self.axes.set_ylabel(self.ylabel)
40
41        self.canvas = FigureCanvasTkAgg(self.figure, master=container)
42        self.canvas_widget = self.canvas.get_tk_widget()
43        self.canvas_widget.pack(fill="both", expand=True)
44
45        self.color_map: dict[str, str] = {
46            "Easy": "green",
47            "Medium": "orange",
48            "Hard": "red"
49        }
title
xlabel
ylabel
figure
axes
canvas
canvas_widget
color_map: dict[str, str]
def plot_line(self, x, y, label=None):
52    def plot_line(self, x, y, label=None):
53        self.axes.clear()
54        self.axes.set_title(self.title)
55        self.axes.set_xlabel(self.xlabel)
56        self.axes.set_ylabel(self.ylabel)
57        stages = list(range(1, 11))
58        self.axes.set_xlim(1, 10)
59        self.axes.xaxis.set_major_locator(FixedLocator(stages))
60
61        self.axes.plot(
62            x, 
63            y, 
64            linestyle=':', # dotted lines
65            marker='o',    # dots on the points
66            linewidth=3,   # thicker lines
67            markersize=6,  # bolder points
68            label=label, 
69            color='black'
70        )
71        # self.axes.legend(
72        #     handlelength=4,    # longer lines in legend
73        #     markerscale=1,     # dot scale in legend
74        #     handletextpad=0.2, # padding with text
75        #     borderaxespad=0.2, # padding from border
76        # )
77
78        self.axes.grid(True)
79        self.canvas.draw()
def plot_multi_line(self, series: list[tuple[list, list, str]]):
 81    def plot_multi_line(self, series: list[tuple[list, list, str]]):
 82        self.axes.clear()
 83        self.axes.set_title(self.title)
 84        self.axes.set_xlabel(self.xlabel)
 85        self.axes.set_ylabel(self.ylabel)
 86        stages = list(range(1, 11))
 87        self.axes.set_xlim(1, 10)
 88        self.axes.xaxis.set_major_locator(FixedLocator(stages))
 89
 90        for x, y, label in series:
 91            self.axes.plot(
 92                x, 
 93                y, 
 94                linestyle=':', # dotted lines
 95                marker='o',    # dots on the points
 96                linewidth=3,   # thicker lines
 97                markersize=6,  # bolder points
 98                label=label, 
 99                color=self.color_map[label] # map colour to difficulty
100            )
101        self.axes.legend(
102            handlelength=0.5,    # longer line in legend
103            markerscale=1,     # dot scale in legend
104            handletextpad=0.4, # padding with text
105            borderaxespad=0.2, # padding from border
106        )
107        self.axes.grid(True)
108        self.canvas.draw()