The renderers  that you pass on to the `plot` function can be manipulated 
outside the call to plot, so you can read the datasets you need, construct 
a renderer for each one, group them in a list and pass them on to plot.  I 
am not familiar with Matlab, but based on your description, you can 
implement hold-on and hold-off as follows:

#lang racket
(require plot)

(define the-renderers '())

(define (hold-on renderer)
  (set! the-renderers (cons renderer the-renderers)))

(define (hold-off)
  (begin0
    (plot (reverse the-renderers))
    (set! the-renderers '())))

;; add a renderer for SIN
(hold-on (function sin 0 10))

;; add a renderer for COS
(hold-on (function cos 0 10))

;; Show the plot
(hold-off)

Alternatively, if you want a separate plot for each function, you can 
implement hold-off as follows:

(define (hold-off-2)
  (begin0
    (for/list ([renderer (reverse the-renderers)])
      (plot renderer))
    (set! the-renderers '())))

Alex.

On Thursday, April 9, 2020 at 2:35:04 PM UTC+8, greadey wrote:
>
> Hi All,
>
> Can anyone give me some pointers on plotting multiple data sets on one set 
> of axes.  Plotting two or more data sets on one set of axes is easy if you 
> know in advance what the data is called;
>
> (plot (list
>       (lines set1)
>       (points set2))
>      #:x-label "x" #:y-label "y")
>
> however I have a list of data sets generated from reading a bunch of files 
> in a directory and I wish to loop through the list and add each data-set to 
> an existing set of axes.
>
> Iterating through the data and plotting each set results in multiple plot 
> windows.
>
> In summary I am looking for something similar to Matlab's "hold on" e.g.
>
> ;Pseudo Matlab code
>
> figure()
> for idx = 1 : numel(list-of (list-of vector-pairs))
>     plot(list-of (list-of vector-pairs))(idx)
>     hold on
> end
> hold off
>
> I have got (plot-new-window? #t), however as far as I know this is just 
> causing a plot to appear in a new window rather than directly in the repl.
>
> Many thanks,
>
> greadey.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/ec890e78-b254-4e7e-9970-6f0d46f50c20%40googlegroups.com.

Reply via email to