7

I have a breed called players. Each player-owns a player-strategy. There are 6 possible player-strategies. When I write

histogram [player-strategy] of players

nothing appears on my plot.

I have one plot with one pen -- and don't set either the plot or penname. plot-name returns the plot. pen-mode is bar. interval is 1.0

I don't know how to ask for the current penname. But since the plot has only one pen it shouldn't matter.

The histogram command is in both plot-update and pen-update. I've tried it in both together or one at a time. I also tried in code. Makes no difference.

What do I have to do to get a histogram to appear?

RussAbbott
  • 2,660
  • 4
  • 24
  • 37

2 Answers2

10

OK, here is what I think you are after.

If you create the following plot:

plot setup

And write the following code:

extensions [table]
breed [players player]
players-own [player-strategy]

to setup
  clear-all
  create-players 100 [ set player-strategy one-of ["a" "b" "c" "d" "e"] ]
  reset-ticks
end

to update-strategy-plot
  set-current-plot "Player strategies"
  clear-plot
  let counts table:counts [ player-strategy ] of players
  let strategies sort table:keys counts
  let n length strategies
  set-plot-x-range 0 n
  let step 0.05 ; tweak this to leave no gaps
  (foreach strategies range n [ [s i] ->
    let y table:get counts s
    let c hsb (i * 360 / n) 50 75
    create-temporary-plot-pen s
    set-plot-pen-mode 1 ; bar mode
    set-plot-pen-color c
    foreach (range 0 y step) [ _y -> plotxy i _y ]
    set-plot-pen-color black
    plotxy i y
    set-plot-pen-color c ; to get the right color in the legend
  ])
end

You should get the following plot:

plot result

I believe this should answer your previous question as well.

(Note that I've put the plotting code in a code tab procedure, but you could just as well stick it in the "Plot update commands" field.)

Community
  • 1
  • 1
Nicolas Payette
  • 14,847
  • 1
  • 27
  • 37
  • Thank you very much. Haven't tried it yet, but the result is just what I want. [ A lot more code than I expected :) ] – RussAbbott Mar 06 '18 at 15:47
  • Clever but also dismaying. https://github.com/NetLogo/NetLogo/issues/1586 – Alan Mar 06 '18 at 17:56
  • 2
    The NetLogo development team has limited resources. But NetLogo is open source. Contributions, or money to fund contributions, would always be welcome. – Nicolas Payette Mar 06 '18 at 18:00
1

I know it is a very old question, but in case anyone lands here on a search. The current version of NetLogo comes with example code for histogram usage: look in the file menu under 'Models Library'; see 'Code Examples'/'Histogram Example'.