Plotting¶
PyLinkbot3 comes with a helper function to facilitate plotting graphs. The function can be used on PC environments as well as with the Linkbot-Hub.
-
linkbot3.scatter_plot(*args, **kwargs)¶ A helper function to generate and display graphical plots.
Parameters: args – These arguments are passed directly to matplotlib.pyplot.plot. Please see: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot
If the process is being executed as a Prex child process, the arguments should be in the format: [xs], [ys], [xs], [ys], ... etc.
import linkbot3 as linkbot
class MotorPlot():
def __init__(self):
self.angles = []
self.times = []
def cb(self, angle, timestamp):
print('cb', angle, timestamp)
self.angles.append(angle)
self.times.append(timestamp)
l = linkbot.Linkbot('ZRG6')
l.motors.reset()
l.motors.move([0,0,0], relative=False)
myplot = MotorPlot()
l.motors[0].set_event_handler(myplot.cb)
l.motors[0].set_controller(linkbot.peripherals.Motor.Controller.SMOOTH)
l.motors[0].set_accel(30)
l.motors[0].set_decel(30)
l.motors[0].move(360)
print('Plotting...')
linkbot.scatter_plot(myplot.times, myplot.angles)