Netlogo 图直方图百分比
Netlogo Plot Histogram Percentage
我正在尝试在 NetLogo 中创建一个直方图,它显示列表中每个唯一值的百分比而不是频率。假设我们有一个列表 [1 1 2 5]
,那么直方图应该有 3 个柱对应于以下点:
Bar1-->(x:1, y:0.5)
Bar2-->(x:2, y:0.25)
Bar3-->(x:5, y:0.25)
要制作条形图,我认为最简单的方法可能是使用 NetLogo 中的 plotxy
函数。使用此设置:
globals [ example_list ]
to setup
ca
set example_list [ 1 1 2 5 ]
reset-ticks
end
A to-report
获取列表中项目的频率:
to-report freq [ i_ list_ ]
report length filter [ ind -> ind = i_ ] list_
end
然后 to-report
找到每个传递的唯一值的比例,并输出该值与唯一值的配对(评论中有更多详细信息):
to-report freq_map [ list_ ]
; get length of input list
let len length list_
; get unique values for the input list
let uniques remove-duplicates list_
; get counts of each unique value
let counts map [ i -> freq i list_ ] uniques
; report an xy pair for each unique value / proportion
report ( map [ [ x y ] -> list x ( y / len ) ] uniques counts )
end
现在,您可以将列表传递给 freq_map
,它将输出一个 xy 对列表列表:
observer> show freq_map [ 1 1 2 5 ]
observer: [[1 0.5] [2 0.25] [5 0.25]]
您现在可以设置您的剧情了。如果对这些对中的每一对使用 foreach
到 plotxy
,如下所示:
只要您使用 X max
和 Y max
设置正确缩放它,您的情节就会像这样:
我正在尝试在 NetLogo 中创建一个直方图,它显示列表中每个唯一值的百分比而不是频率。假设我们有一个列表 [1 1 2 5]
,那么直方图应该有 3 个柱对应于以下点:
Bar1-->(x:1, y:0.5)
Bar2-->(x:2, y:0.25)
Bar3-->(x:5, y:0.25)
要制作条形图,我认为最简单的方法可能是使用 NetLogo 中的 plotxy
函数。使用此设置:
globals [ example_list ]
to setup
ca
set example_list [ 1 1 2 5 ]
reset-ticks
end
A to-report
获取列表中项目的频率:
to-report freq [ i_ list_ ]
report length filter [ ind -> ind = i_ ] list_
end
然后 to-report
找到每个传递的唯一值的比例,并输出该值与唯一值的配对(评论中有更多详细信息):
to-report freq_map [ list_ ]
; get length of input list
let len length list_
; get unique values for the input list
let uniques remove-duplicates list_
; get counts of each unique value
let counts map [ i -> freq i list_ ] uniques
; report an xy pair for each unique value / proportion
report ( map [ [ x y ] -> list x ( y / len ) ] uniques counts )
end
现在,您可以将列表传递给 freq_map
,它将输出一个 xy 对列表列表:
observer> show freq_map [ 1 1 2 5 ]
observer: [[1 0.5] [2 0.25] [5 0.25]]
您现在可以设置您的剧情了。如果对这些对中的每一对使用 foreach
到 plotxy
,如下所示:
只要您使用 X max
和 Y max
设置正确缩放它,您的情节就会像这样: