Пример #1
0
    def UserFigure(data, p, figure=None, special=None):
        if figure is None:
            return MCLogTab.UserFigure(
                data, p, MCLogTab.MakeFigure(p.type, data, p.x, p.y1, p.y2),
                special)
        if special is None:
            return MCLogTab.UserFigure(
                data, p, figure,
                lambda y, idx, id_: UserPlot(y, figure, idx, id_))

        def set_label(label_fn, label_size_fn, label):
            if len(label.text):
                label_fn(label.text)
                label_size_fn(label.fontsize)

        set_label(figure.title, figure.title_fontsize, p.graph_labels.title)
        set_label(figure.x_label, figure.x_label_fontsize,
                  p.graph_labels.x_label)
        set_label(figure.y1_label, figure.y1_label_fontsize,
                  p.graph_labels.y1_label)
        set_label(figure.y2_label, figure.y2_label_fontsize,
                  p.graph_labels.y2_label)

        def handle_yd(yds, idx):
            for yd in yds:
                match = re.match("(.*)_(.*)$", yd)
                if match is None:
                    special(yd, idx, "diff")
                elif match.group(2) in ["rpy", "r", "p", "y"]:
                    special(match.group(1), idx, match.group(2))
                else:
                    special(match.group(1), idx, "diff")

        handle_yd(p.y1d, 0)
        handle_yd(p.y2d, 1)
        if not isinstance(p.grid1, LineStyle):
            figure._left().grid = LineStyle(**p.grid1)
        else:
            figure._left().grid = p.grid1
        if figure._right() is not None:
            if not isinstance(p.grid2, LineStyle):
                figure._right().grid = LineStyle(**p.grid2)
            else:
                figure._right().grid = p.grid2
        for y, s in p.style.iteritems():
            figure.style_left(y, s)
        for y, s in p.style2.iteritems():
            figure.style_right(y, s)
        for param, value in p.extra.iteritems():
            getattr(figure, param)(value)
        return figure
Пример #2
0
def load_UserPlots(fpath):
    if not os.path.exists(fpath):
      return []
    userPlotList = []
    with open(fpath) as f:
      userPlotList = [UserPlot(*x) for x in json.load(f)]
      for i,plt in enumerate(userPlotList):
        for y in plt.style:
          plt.style[y] = LineStyle(**plt.style[y])
        for y in plt.style2:
          plt.style2[y] = LineStyle(**plt.style2[y])
        if not isinstance(plt.graph_labels, GraphLabels):
          for key, value in plt.graph_labels.items():
            plt.graph_labels[key] = TextWithFontSize(**plt.graph_labels[key])
          userPlotList[i] = plt._replace(graph_labels = GraphLabels(**plt.graph_labels))
    return userPlotList
Пример #3
0
 def apply(self):
   for y,widgets in self.plotWidgets.iteritems():
     label = widgets[0].text()
     linestyle = widgets[1].currentText()
     linewidth = float(widgets[2].text())
     color = widgets[3].color.name()
     st = LineStyle(label = label, linestyle = linestyle, linewidth = linewidth, color = color)
     self.style(y, st)
   self.canvas.draw()
Пример #4
0
    def __init__(self):
        self.fig = matplotlib.pyplot.figure(figsize=(5, 4), dpi=100)
        self.axes = self.fig.add_subplot(111)
        self.axes.autoscale(enable=True, axis='both', tight=False)
        self.axes.autoscale_view(False, True, True)
        self.axes2 = self.axes.twinx()
        self.axes2.autoscale_view(False, True, True)
        self.axes_format_coord = self.axes.format_coord
        self.axes2_format_coord = self.axes2.format_coord
        self.axes.format_coord = self.format_coord
        self.axes2.format_coord = self.format_coord

        self.grid = LineStyle()
        self.grid2 = LineStyle()

        self._x_label_fontsize = 10
        self._y1_label_fontsize = 10
        self._y2_label_fontsize = 10
        self._labelpad = 10
        self._tick_labelsize = 10
        self._legend_fontsize = 10
        self._top_offset = 0.9
        self._bottom_offset = 0.1
        self._y1_legend_ncol = 3
        self._y2_legend_ncol = 3

        self.data = None
        self.computed_data = {}
        self.axes_plots = OrderedDict()
        self.axes2_plots = OrderedDict()

        self.color = 0
        self.Ncolor = 12
        # self.colors = ['r', 'g', 'b', 'y', 'k', 'cyan', 'magenta', 'orange']
        cm = matplotlib.cm.Set1
        cm2rgb = (np.array(cm(x)[0:3]) for x in np.linspace(0, 1, self.Ncolor))
        self.colors = [
            '#%02x%02x%02x' % tuple((255 * rgb).astype(int)) for rgb in cm2rgb
        ]

        self.x_data = 't'
Пример #5
0
 def style(self, y, style=None):
     if y not in self.plots:
         raise KeyError("No plot named {}".format(y))
     plt = self.plots[y]
     if style is None:
         return LineStyle(plt.get_color(),
                          plt.get_linestyle(),
                          plt.get_linewidth(),
                          label=plt.get_label())
     plt.set_color(style.color)
     plt.set_linestyle(style.linestyle)
     plt.set_linewidth(style.linewidth)
     if len(style.label):
         plt.set_label(style.label)
Пример #6
0
 def _plot(self,
           x,
           y,
           y_label,
           style=None,
           filter_=None,
           z=None,
           source=None):
     if type(y[0]) is unicode:
         if filter_ is not None:
             return False
         return self._polyAxis._plot_string(x, y, y_label, style)
     if style is None:
         return self._plot(x,
                           y,
                           y_label,
                           LineStyle(color=self.figure._next_color()),
                           filter_=filter_,
                           z=z,
                           source=source)
     if y_label in self.plots:
         return False
     self._axis.get_yaxis().set_visible(True)
     self.data[y_label] = [x, y, z, filter_]
     if filter_ is not None:
         x = self._filter(x, filter_)
         y = self._filter(y, filter_)
         z = self._filter(z, filter_)
         self.filtered[y_label] = [x, y, z]
     else:
         self.filtered[y_label] = None
     self.source[y_label] = source
     if z is None:
         self.plots[y_label] = self._axis.plot(x,
                                               y,
                                               label=y_label,
                                               color=style.color,
                                               linestyle=style.linestyle,
                                               linewidth=style.linewidth)[0]
     else:
         self.plots[y_label] = self._axis.plot(x,
                                               y,
                                               z,
                                               label=y_label,
                                               color=style.color,
                                               linestyle=style.linestyle,
                                               linewidth=style.linewidth)[0]
     self.legend()
     return True
Пример #7
0
 def _style(self, plots, y, styleIn=None):
     if not y in plots:
         raise KeyError("No plot named {}".format(y))
     plt = plots[y]
     if styleIn is None:
         return LineStyle(plt.get_color(),
                          plt.get_linestyle(),
                          plt.get_linewidth(),
                          label=plt.get_label())
     else:
         plt.set_color(styleIn.color)
         plt.set_linestyle(styleIn.linestyle)
         plt.set_linewidth(styleIn.linewidth)
         if len(styleIn.label):
             plt.set_label(styleIn.label)
Пример #8
0
 def __init__(self, parent, x_axis=None, poly=None, _3D=False):
     self.figure = parent
     self._3D = _3D
     if x_axis is None:
         self.is_left = True
         if not _3D:
             self._axis = parent.fig.add_subplot(111)
         else:
             self._axis = parent.fig.gca(projection='3d')
             self._axis.set_xlabel('X')
             self._axis.set_ylabel('Y')
             self._axis.set_zlabel('Z')
         self._axis.autoscale(enable=True, axis='both', tight=False)
         self._x_axis = self._axis
     else:
         self.is_left = False
         if not _3D:
             self._axis = x_axis.twinx()
         else:
             self._axis = x_axis
         self._x_axis = x_axis
     if poly is None and not _3D:
         self._polyAxis = PlotPolygonAxis(parent, self._axis)
     else:
         self._polyAxis = poly
     self._axis.set_facecolor((1, 1, 1, 0))
     box = self._axis.get_position()
     self._axis.autoscale_view(False, True, True)
     self._axis.format_coord = parent.format_coord
     self._axis.get_yaxis().set_visible(False)
     self.grid = LineStyle(linestyle='--')
     self.plots = OrderedDict()
     self._label_fontsize = 10
     self._z_label_fontsize = 10
     self._legend_ncol = 3
     self.source = {}
     self.data = {}
     self.filtered = {}
Пример #9
0
  def __init__(self, parent = None):
    super(MCLogUI, self).__init__(parent)
    self.__init__ui = ui.MainWindow()
    self.ui = ui.MainWindow()

    self.ui.setupUi(self)

    self.tab_re = re.compile('^Plot [0-9]+$')

    self.data = {}

    self.gridStyles = {'left': LineStyle(), 'right': LineStyle(linestyle = ':') }
    self.gridStyleFile = os.path.expanduser("~") + "/.config/mc_log_ui/grid_style.json"
    if os.path.exists(self.gridStyleFile):
      with open(self.gridStyleFile) as f:
        data = json.load(f)
        for k in self.gridStyles.keys():
          if k in data:
            self.gridStyles[k] = LineStyle(**data[k])
    UserPlot.__new__.__defaults__ = (self.gridStyles['left'], self.gridStyles['right'], {}, {}, GraphLabels(), {})

    self.robotFile = os.path.expanduser("~") + "/.config/mc_log_ui/robot"
    self.userPlotFile = os.path.expanduser("~") + "/.config/mc_log_ui/custom_plot.json"
    self.userPlotList = load_UserPlots(self.userPlotFile)
    self.update_userplot_menu()

    self.activeRobotAction = None
    self.rm = None
    if mc_rbdyn is not None:
      rMenu = QtGui.QMenu("Robot", self.ui.menubar)
      rGroup = QtGui.QActionGroup(rMenu)
      rCategoryMenu = {}
      rActions = []
      for r in mc_rbdyn.RobotLoader.available_robots():
        rAct = RobotAction(r, rGroup)
        rAct.setCheckable(True)
        rGroup.addAction(rAct)
        if '/' in r:
          category, name = r.split('/', 1)
          if not category in rCategoryMenu:
            rCategoryMenu[category] = QtGui.QMenu(category)
          rAct.setText(name)
          rAct.actual(r)
          rCategoryMenu[category].addAction(rAct)
        else:
          rActions.append(rAct)
      rMenu.addActions(rActions)
      for category in sorted(rCategoryMenu):
          rMenu.addMenu(rCategoryMenu[category])
      defaultBot = self.getDefaultRobot()
      if defaultBot in mc_rbdyn.RobotLoader.available_robots():
        actionIndex = mc_rbdyn.RobotLoader.available_robots().index(defaultBot)
        defaultBot = rGroup.actions()[actionIndex]
      else:
        defaultBot = rGroup.actions()[0]
      self.activeRobotAction = defaultBot
      self.activeRobotAction.setChecked(True)
      self.setRobot(self.activeRobotAction)
      self.connect(rGroup, QtCore.SIGNAL("triggered(QAction *)"), self.setRobot)
      self.ui.menubar.addMenu(rMenu)

    self.styleMenu = QtGui.QMenu("Style", self.ui.menubar)

    # Line style menu
    self.lineStyleMenu = QtGui.QMenu("Graph", self.styleMenu)
    def fillLineStyleMenu(self):
      self.lineStyleMenu.clear()
      canvas = self.getCanvas()
      def makePlotMenu(self, name, plots, style_fn):
        if not len(plots):
          return
        menu = QtGui.QMenu(name, self.lineStyleMenu)
        group = QtGui.QActionGroup(act)
        action = QtGui.QAction("All", group)
        action.triggered.connect(lambda: AllLineStyleDialog(self, name, self.getCanvas(), plots, style_fn).exec_())
        group.addAction(action)
        sep = QtGui.QAction(group)
        sep.setSeparator(True)
        group.addAction(sep)
        for y in plots:
          style = style_fn(y)
          action = QtGui.QAction(style.label, group)
          action.triggered.connect(lambda yin=y,stylein=style: LineStyleDialog(self, yin, self.getCanvas(), stylein, style_fn).exec_())
          group.addAction(action)
        menu.addActions(group.actions())
        self.lineStyleMenu.addMenu(menu)
      makePlotMenu(self, "Left", canvas.axes_plots.keys(), canvas.style_left)
      makePlotMenu(self, "Right", canvas.axes2_plots.keys(), canvas.style_right)
    self.lineStyleMenu.aboutToShow.connect(lambda: fillLineStyleMenu(self))
    self.styleMenu.addMenu(self.lineStyleMenu)

    # Grid style menu
    self.gridStyleMenu = QtGui.QMenu("Grid", self.styleMenu)
    self.gridDisplayActionGroup = QtGui.QActionGroup(self.gridStyleMenu)
    self.gridDisplayActionGroup.setExclusive(True)
    self.leftGridAction = QtGui.QAction("Left", self.gridDisplayActionGroup)
    self.leftGridAction.triggered.connect(lambda: GridStyleDialog(self, "left", self.getCanvas(), self.getCanvas().grid).exec_())
    self.gridDisplayActionGroup.addAction(self.leftGridAction)
    self.rightGridAction = QtGui.QAction("Right", self.gridDisplayActionGroup)
    self.rightGridAction.triggered.connect(lambda: GridStyleDialog(self, "right", self.getCanvas(), self.getCanvas().grid2).exec_())
    self.gridDisplayActionGroup.addAction(self.rightGridAction)
    self.gridStyleMenu.addActions(self.gridDisplayActionGroup.actions())
    self.styleMenu.addMenu(self.gridStyleMenu)

    # Labels
    self.titleAction = QtGui.QAction("Labels/Title/Fonts", self.styleMenu)
    self.titleAction.triggered.connect(lambda: LabelsTitleEditDialog(self, self.getCanvas()).exec_())
    self.styleMenu.addAction(self.titleAction)

    self.ui.menubar.addMenu(self.styleMenu)

    self.toolsMenu = QtGui.QMenu("Tools", self.ui.menubar)
    act = QtGui.QAction("Dump qOut to seqplay", self.toolsMenu)
    act.triggered.connect(DumpSeqPlayDialog(self).exec_)
    self.toolsMenu.addAction(act)
    self.ui.menubar.addMenu(self.toolsMenu)

    self.addApplicationShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_O, self.shortcutOpenFile)
    self.addApplicationShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_W, self.shortcutCloseTab)
    self.addApplicationShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_PageDown, self.shortcutNextTab)
    self.addApplicationShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_PageUp, self.shortcutPreviousTab)
    self.addApplicationShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_T, self.shortcutNewTab)
    self.addApplicationShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_S, self.save_userplot)
    self.addApplicationShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_A, self.shortcutAxesDialog)