I started to use netlogo and I would like to add a legend to the model.
I didn't found any way to do it.
Is there some standard way to do it?
I thought about adding image to the interface but I didn't find any way to do it. For example I want that user will know is the green particle means and what the read means
You can use the bitmap extension. Here is a result example:
the code:
extensions [bitmap]
....
let legend bitmap:import "symbology.png"
bitmap:copy-to-drawing legend 40 275
"symbology.png" is the name of the graphics file, and 40 275 are the location coordinates. You will have to test several image sizes and coordinates until it suits your needs.
I don't know a great way to do this, the closest I've ever been able to get is to use a combination of specific plot
set-ups and note
widgets. As an example, start out with a plot called "Legend" with this setup to start:
Now size it to look something like this:
Now make a procedure to 'draw' legend guides (some detail in comments):
to setup-legend-plot
; Choose correct plot
set-current-plot "Legend"
clear-plot
; Define starting y and color
let starts [ [ 10 green ] [ 7 red ] [ 4 blue ] ]
; for each value in starts
foreach starts [ start ->
; make a range of values starting at the initial
; y value from 'starts'
let s first start
let f s - 2.5
let ran ( range s f -0.01 )
create-temporary-plot-pen "temp"
set-plot-pen-color last start
; draw lines at each y value to make it
; look like a solid drawing
foreach ran [ y ->
plot-pen-up
plotxy 1 y
plot-pen-down
plotxy 2 y
]
]
end
Calling setup-legend-plot
should now make your "Legend" plot look like
Now you can make some note
widgets and layer them over the blank space in the plot:
Not exactly straightforward, but definitely the closest I've found.
Edit:
"Closest I've found for building a legend within NetLogo." Javier's answer is a far better approach if you can swing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With