问题描述
您好netlogo社区
Hello netlogo community
我有一个简单的模型,其中有100只海龟,每只都有一个称为能量的变量.我该如何绘制一个图表来绘制世界上每只乌龟的能量我是说:x轴每只乌龟与乌龟相关的y轴能量
I have a simple model with 100 turtles and each one has a variable called energy.How can I draw a graph that plots for each turtle in the world his energyI mean:x-axis each turtley-axis energy associated to the turtle
抱歉,我认为这是一个简单的问题,但我可以弄清楚该怎么做.理想情况下,我想要一个如下的直方图:
Sorry I think is an easy question but I can figure out how to do it.Ideally I would like an histogram like the following:
推荐答案
NetLogo histogram
命令不允许您逐个绘制每个值,但是自己编写代码并不难.
The NetLogo histogram
command won't allow you to plot each value individually, but it's not too hard to code it yourself.
假设您有一个包含以下代码的模型:
Supposing you have a model with the following code:
turtles-own [ energy ]
to setup
clear-all
create-turtles 100 [ set energy random 100 ]
reset-ticks
end
您可以使用定义如下的笔添加绘图:
You can add a plot with a pen that is defined like this:
(别忘了将笔模式设置为"Bar"!)
(Don't forget to set the pen mode to "Bar"!)
要获得这样的情节:
请注意,这使用了新的NetLogo 6.0匿名过程语法.在NetLogo< = 5.3.1中,您将使用[ ask ? [ plot energy ] ]
而不是[ [t] -> ask t [ plot energy ] ]
.
Note that this uses the new NetLogo 6.0 anonymous procedure syntax. In NetLogo <= 5.3.1, you'd use [ ask ? [ plot energy ] ]
instead of [ [t] -> ask t [ plot energy ] ]
.
还请注意, sort
会对您的海龟进行排序who
号.如果您希望使用其他顺序,请使用 sort-on
.
Also note that sort
will sort your turtles by who
number. Use sort-on
if you prefer a different order.
这篇关于情节乌龟vs能量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!