Dynamically replotting every tick - netlogo

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!

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:

Related

Update some plots in NetLogo

Is it possible to have plots that are updated at different time points?
My model looks like that (it is replicator dynamics):
to go
repeat 10 [do-something]
replicate
tick
end
Then I would like to have one plot that is updated on tick, just like usual, and the second one that is updated at do-something and then reset at tick.
I tried to find a solution in documentation but update-plots command updates ALL plots which is not what i want.
You can use the various manual plotting commands (eg plotxy, plot-pen-down, plot-pen-up) to explicitly plot things, see the plotting section of the user manual, but is often simpler to have the plot commands in the plot rather than the code.
To do it in the plot instead of code, you could change to a structure like this (if your full code is suitable):
to go
do-something
if ticks mod 10 = 0 [ replicate ]
tick
end
and use the automatic update of plots with tick. You would also use the if ticks mod 10 = 0 trick in the update section of your plot.

First point of gradient change in matlab

I'm looking to automate the finding of a location on a plot.
this is the plot
I want my code to automatically find the point where the plot smoothes out. The point that is highlighted in the plot. I did this by hand with the selector tool, but I need to do it for many different plots, so selecting them each by hand would take too long.
Is there anyway to automate this process?

Netlogo how does time relate to ticks?

I noticed that my tick counter does not show the same as the time in my plots. It seems 1 tick is roughly equal to 2 units of time on my graphs.
I would have thought that the time in plots was related to ticks, but this doesnt seem to be the case.
How does these two relate?
If you want absolute control over both coordinates of the points you are plotting, use plotxy instead of plot.
If you just use plot, then the x coordinate just ends up being "how many times I've called plot". If you always call plot exactly once per tick, that will equal the number of ticks.
Perhaps you are, without realizing it, calling plot either more or less frequently than that...? Note that it's possible (and recommended) to have all of your plotting code inside plots, but you might also (or instead) have plotting code in the Code tab.
If you can tell us more about how you define your time unit in your graph we might be able to help you more, but as far as I know a tick 's length is all dependent on computation and its the time taken to iterate through your Go (or whenever you defined tick from start to end once! )
But you can use timer for measuring time taken after resetting timer in milliseconds :
http://ccl.northwestern.edu/netlogo/docs/dict/timer.html
In your problem, I think it's better to check interval in your plot, if it's anything other than 1 it means it does not update your plot every tick ,

How to change plot background color in NetLogo

Is there a way to change the background color of a plot window in NetLogo?
(I want turtles to be black and white, and I'd like plot pens for statistics on the two kinds of turtles to match their colors. A white pen is not visible on a white background, obviously.)
Thanks.
NetLogo has not built-in way to change the background color of a plot. Arguably, this is something it should have. If you feel strongly enough about it, I would suggest sending a feature request to feedback#ccl.northwestern.edu or even opening an issue directly on GitHub.
Now, in the meanwhile, is there a way around it? Well, I feel almost dirty for even suggesting it, but you could do something like this:
Create a new plot pen of the color you wish your background to be, and set it to "line mode". This pen has to be the first one in your plot pen list so it's drawn before the other pens. (This might require deleting your other pens and recreating them, as NetLogo doesn't have an easy way to reorder plot pens, I think.)
Now put the following in your pen's update commands:
plot-pen-reset
let y plot-y-min
while [ y <= plot-y-max ] [
plotxy plot-x-min y
plotxy plot-x-max y
set y y + 0.05
]
This will draw lines, one by one, to fill your background. Depending on the size of your plot on the screen, you might want to play with the "interval" (0.05 here) to find the biggest value that doesn't leave white lines.
Be warned: this will slow down your model. If your plot axis are never rescaled, however, maybe you can get away with putting the code in your pen's setup commands so it's only executed once.

CorePlot polar plot

It became apparent that I needed to attempt to modify CorePlot code to allow me to plot Polar/Radar plots, due to heavy memory usage trying to plot circles/spokes as ScatterPlots.
I realised I could continue to use CPTScatterPlot for the actual polar data, however somehow I needed to modify the drawGridLinesInContext, such that instead of straight lines at each location, CPTXCoordinate would draw the circular line, CPTYCoordinate would be ignored, and CPTZCoordinate would draw the spokes.
I had to create new classes based on their XY siblings viz CPTPolarGraph, CPTPolarPlotSpace, CPTPolarAxisSet, CPTPolarAxis. The new code continues to use X and Y axis to plot those axes, however a Z axis was introduced to manage the spokes.
Now I seem to have cracked this, however if I scroll up and down, the circles continue to pass through the X and Y axis ticks, as they should do, but when I scroll left and right, the circles get redrawn and no longer sit on the ticks.
I obviously got some more debugging to do here, but was hoping for some pointers from the CorePlot crew, as to what might be happening
.
I can zip my modified version of CorePlot_1.1, including a example polar scatter plot, and forward if needs be.
The positioning of the centreViewPoint tracks precisely, as the spokes are always generated from the same point, wherever the centre is in the plotArea. The rings are also always generated from the same centre.
It seems to me that somehow, the diameters of the rings when I scroll left right get changed from the first plot presentation, yet when I scrolled Up-down they don't. Notice that when the plot is scrolled to left edge or right edge the major rings are line up on the major ticks again, as are the minor.
I tried reversing the code such that only the CPTCoordinateY get plotted, and I see the same effect, except scrolling up-down exhibits the changing in ring diameter size.
Now perhaps CGPoint startViewPoint = [thePlotSpace plotAreaViewPointForPlotPoint:startPlotPoint]; which establishes the diameter of a ring from its x-coordinate, is not returning correctly. Although perhaps also the locations set are changing, but why should they if no zooming has been done.
I'm kind of struggling here, as when I walk through the code the locations don't appear to change.
This is likely a pixel alignment issue. The tick drawing code aligns the tick marks with the pixel grid but the new axis drawing does not. Look at CPTAlignRectToUserSpace() and the other alignment functions in CPTUtilities.h.
Edit:
You also may need a custom setter method for the zRange in the plot space. Make it similar to the xRange and yRange setters. The notifications fired by these methods are important—they force other parts of the graph to redraw when the plot space changes.