sliding-plot


Information

Created with NetLogo version NetLogo 3.0.2
Running with NetLogoLite.jar version 302.


WHAT IS IT?


A small example of a sliding plot

HOW IT WORKS


It stores the data in a list. The oldest data (the last list item) is removed. The whole plot is cleared, then the whole list is plotted. This produces a sliding plot.

THINGS TO NOTICE


If the plot parameters (min/max x and y ranges) are not set correctly for the data, and auto-plot is on, the plot will blink and jump unattractively.

Procedures

NetLogo Version: NetLogo 3.0.2

;;;;SUMMARY
;; An example of a sliding plot
;;;; COPYRIGHT
;; Copyright (C) 2006 James P. Steiner
;; Some Rights Reserved.
;; Licenced under Creative Commons 2.0 by-sa-nc license
;;
globals [ tick plot-list opx ]

to setup 
   ca
   set plot-list n-values 200 [ 0 ]
   cct 1 [ pd set pen-size 2 ]
   set opx 0
   
end

to sliding-plot [ new-plot-data ]
     set plot-list lput (new-plot-data) (but-first plot-list)
     if tick mod 2 = 0
     [ clear-plot
       foreach plot-list [ plot ? ]
     ]
end
   
to normal-plot [ new-plot-data ]
   plot new-plot-data
end
      
to demo
     no-display
      let new-plot-data random-float 2 + (10 * sin tick  * cos (tick * 2) )
    
     ask turtle 0 
     [ set color timer
       setxy   (xcor + .2) new-plot-data
       if xcor >= screen-edge-x [ pu set xcor (- screen-edge-x)] ; max-pxcor [ pu ] 
       if xcor <= (- screen-edge-x) [ pd ] ; min-pxcor
       if opx != pxcor
       [  ask patches with [ pxcor = pxcor-of myself ]
          [  set pcolor scale-color color-of myself pycor (- screen-edge-y)  new-plot-data ]
             set opx pxcor  
          ]     
     ]
     if xcor-of turtle 0 = (- screen-edge-x) [ wait .25 cd ]

     ifelse sliding-plot?
     [ sliding-plot new-plot-data ]
     [ normal-plot new-plot-data ]
     
     set tick tick + 1
     display
 end
   
   

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download sliding-plot --