From 4bc5c68db7cad55cc351cf84ceb75fd510cf0fe4 Mon Sep 17 00:00:00 2001 From: Johannes Mey <johannes.mey@tu-dresden.de> Date: Tue, 21 Jul 2020 01:11:31 +0200 Subject: [PATCH] some changes to plot experiment --- scripts/plotter.py | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/scripts/plotter.py b/scripts/plotter.py index bb3445c..3a9ae7c 100755 --- a/scripts/plotter.py +++ b/scripts/plotter.py @@ -3,16 +3,43 @@ from matplotlib import pyplot as plt import rospy from panda_mqtt_connector.msg import StampedVelocity -def plot_x(msg): - plt.plot(msg.header.stamp.to_sec(), msg.velocity, '*') - plt.axis("equal") - plt.draw() - plt.pause(0.00000000001) +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + +new_velocity = [] + +fig, ax = plt.subplots() +xdata_velocity, ydata_velocity = [], [] +ln, = plt.plot([], [], 'ro') + +def callback_velocity(msg): + global new_velocity + new_velocity += [msg] + +def init_velocity(): + ax.set_xlim(0, 150) + ax.set_ylim(-1.2, 3) + return ln, + +def update_velocity(arg): + print "update", arg + global new_velocity + for msg in new_velocity: + xdata_velocity.append(msg.header.stamp.to_sec()) + ydata_velocity.append(msg.velocity) + ln.set_data(xdata, ydata) + new_velocity = [] + return ln, if __name__ == '__main__': rospy.init_node("plotter") - rospy.Subscriber("panda_mqtt_connector/velocity", StampedVelocity, plot_x) - plt.ion() + rospy.Subscriber("panda_mqtt_connector/velocity", StampedVelocity, callback_velocity) + # plt.ion() + ani = FuncAnimation(fig, update_velocity, None, init_func=init_velocity, blit=True) plt.show() + + rospy.spin() + -- GitLab