Search code examples
histogramnetlogo

How to plot a histogram of distribution of turtles on x-axis in netlogo


In my model, agents are moving. For instance,

breed [guys guy]
breed [infos info]

to setup
create-guys 50 [setxy random-xcor random-ycor]
create-infos 50 [setxy random-xcor random-ycor]
end

to go
ask guys [create-link-to one-of infos
if any? my-links [setxy mean [xcor] of link-neighbors mean [ycor] of link-neighbors ]]
end

I want to draw a histogram showing distribution of turtles that the the both ends of the x-axis of the histogram represent min-pxcor and max-pxcor, while the y-axis of the histogram represents the number of turtles on that pxcor.

I've tried this one.

histogram [count guys-on patch pxcor pycor] of guys

But what I need is a mean of all the pycor at each pxcor.


Solution

  • If what you want is a histogram with the distribution of the count - x-axis as pxcor and y-axis as number of guys on patches with that pxcor, then you can do that with:

    histogram [pxcor] of guys
    

    because turtles have access to the variables of the patch where they are located.

    I think that's what you want from your description. But then you ask about the mean of the pyxor, and I can't see how that is related.