Matplotlib in NRP TF


Hello all,
I am trying to gather and continuously plot weight changes, robot sensory data etc. in a custom diagram so my idea is to call matplotlib from inside a Transfer Function but did not succeed so far.
Is there a way to create a matplotlib gui called inside a TF or what would be the preferred way to create a custom online plot?


Hi Benedikt,

You can call matplotlib by creating a new module under the resources directory in your experiment folder then you need to import plotting function inside the transfer function. To be concrete, if your plot function, say plot_laser_data, located in helpers module you can call this function in the following way.

import helpers   

helpers.plot_laser_data(t, laser_readings, odometer_pos.x, odometer_pos.y)

P.S. without reload it may not work.




Thanks Murat for your contribution.

I confirm that your method indeed works; I have a couple of remarks:

  • Showing a plot window at every timestep (since you are calling your helper function in a TF) will slow down your simulation considerably; to mitigate the effect you could display the plot at every N timesteps.
  • Without reload, any modification to the helpers module will be ignored until the next NRP restart (i.e. cle-kill && cle-start)