| 6 | from pdb import set_trace |
| 7 | |
| 8 | class StatePlotbox(): |
| 9 | def __init__(self, window, args): |
| 10 | ''' Create a new plotbox wrapper object |
| 11 | |
| 12 | Arguments: |
| 13 | window (pg.GraphicsWindow): pyqtgraph window object in which to |
| 14 | place this plotbox |
| 15 | args (PlotboxArgs object): PlotboxArgs object which holds all the |
| 16 | appropriate arguments for the plotbox |
| 17 | |
| 18 | ''' |
| 19 | if not isinstance(args, PlotboxArgs): |
| 20 | raise TypeError('\'args\' argument must be of type PlotboxArgs') |
| 21 | # Initlialize plotbox |
| 22 | if args.labels is not None: |
| 23 | self.plotbox = window.addPlot(title=args.title, labels=args.labels) |
| 24 | else: |
| 25 | self.plotbox = window.addPlot(labels={'left':args.title}) |
| 26 | |
| 27 | # Handle dimension parameters |
| 28 | self.dimension = len(args.plots[0].state_names) |
| 29 | if self.dimension == 1: |
| 30 | self.plotbox.setAutoVisible(y=True) |
| 31 | else: |
| 32 | self.plotbox.setAutoVisible(x=True, y=True) |
| 33 | self.plotbox.setAspectLocked() # Lock x/y ratio to be 1 |
| 34 | |
| 35 | |
| 36 | # Handle color parameters |
| 37 | self.set_axis_color(args.axis_color, args.axis_width) |
| 38 | self.distinct_plot_hues = args.plot_hues |
| 39 | self.plot_min_hue = args.plot_min_hue |
| 40 | self.plot_max_hue = args.plot_max_hue |
| 41 | self.plot_min_value = args.plot_min_value |
| 42 | self.plot_max_value = args.plot_max_value |
| 43 | |
| 44 | if args.legend: |
| 45 | self.add_legend() |
| 46 | |
| 47 | # Plots related to this plotbox |
| 48 | self.plots = {} |
| 49 | for p in args.plots: |
| 50 | self.add_plot(p) |
| 51 | |
| 52 | # Other args |
| 53 | self.time_window = args.time_window |
| 54 | |
| 55 | def label_axes(self, x_label=None, y_label=None): |
| 56 | if x_label is not None: |
| 57 | self.plotbox.setLabel('bottom', x_label) |
| 58 | if y_label is not None: |
| 59 | self.plotbox.setLabel('left', y_label) |
| 60 | |
| 61 | def set_axis_color(self, color, width=1): |
| 62 | self.axis_pen = pg.mkPen(color=color, width=width) |
| 63 | self.plotbox.getAxis("left").setPen(self.axis_pen) |
| 64 | self.plotbox.getAxis("bottom").setPen(self.axis_pen) |
| 65 | |