Sam Marchetti
Sam Marchetti

Reputation: 11

Dynamically replotting every tick

I'm trying to plot two turtle variables against each other in a scatterplot. I want this plot to update continuously, and erase the points from previous steps. I.e. I want one point to move to represent the variable values for one turtle throughout its lifetime, disappearing when it dies and these values equal zero.

This is my code for the pen update commands (isspecials is my turtle agentset)

ask isspecials [plotxy r invader-stride]

I tried adding

reset-plot-pens 

to the end of it, but then nothing appears on the plot. I think it's almost as if I have to create a new pen for each turtle, but I can't tell. I'm really new to this, so if anyone has any suggestions I'd really appreciate it!

Upvotes: 1

Views: 80

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

I tried adding

reset-plot-pens 

to the end of it

Adding plot-pen-reset is the right idea! However, you need to add it before your plotting command.

The plot-pen-reset primitive erases everything that the plot pen has drawn. If you call it right after you plot, you don't get a change to see anything! Calling it just before plotting new stuff will ensure that the stuff you plotted in the previous tick has plenty of time to be seen.

Here is what you plot pen definition should look like:

enter image description here

Upvotes: 1

Related Questions