plot_widget.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 from python_qt_binding.QtCore import Slot, Qt, QTimer, qWarning, Signal
00003 from python_qt_binding.QtGui import QColor
00004 from python_qt_binding.QtWidgets import QWidget, QVBoxLayout, QSizePolicy
00005 from python_qt_binding import QT_BINDING_VERSION
00006 from distutils.version import LooseVersion
00007 from matplotlib.figure import Figure
00008 import operator
00009 import numpy as np
00010 import copy
00011 import threading
00012 import rospy
00013 from trajectory_msgs.msg import JointTrajectory
00014 if LooseVersion(QT_BINDING_VERSION) >= LooseVersion('5.0.0'):
00015     from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
00016 else:
00017     from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
00018 
00019 
00020 class PlotCanvas(FigureCanvas):
00021     def __init__(self):
00022         super(PlotCanvas, self).__init__(Figure())
00023         self.axes = self.figure.add_subplot(111)
00024         self.axes.grid(True, color='gray')
00025         self.figure.tight_layout()
00026         self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
00027         self.updateGeometry()
00028 
00029 
00030 class PlotWidget(QWidget):
00031     def __init__(self, parent=None):
00032         super(PlotWidget, self).__init__(parent)
00033         # create widgets
00034         self.canvas = PlotCanvas()
00035         vbox = QVBoxLayout()
00036         vbox.addWidget(self.canvas)
00037         self.setLayout(vbox)
00038 
00039     def draw_curves(self, curve_names, data):
00040         self.canvas.axes.clear()
00041         self.canvas.axes.grid(True, color='gray')
00042         for name in curve_names:
00043             xdata, ydata = data[name]
00044             self.canvas.axes.plot(xdata, ydata, 'o-', label=name)[0]
00045         self.update_legend()
00046         self.canvas.draw()
00047 
00048     def update_legend(self):
00049         handles, labels = self.canvas.axes.get_legend_handles_labels()
00050         self.canvas.axes.legend(handles, labels, loc='upper left')


rqt_joint_trajectory_plot
Author(s): Ryosuke Tajima
autogenerated on Thu Jun 6 2019 20:46:49