Using Racket to Plot Points

2019-08-05 05:18发布

问题:

After spending some time looking at the documentation, searching the web, and experimenting at the prompt, I haven't succeeded at plotting points using Racket. Could someone post an example of how I'd go about plotting (0 1 2 3 4 5) for my x coordinates and (0 1 4 9 16 25) for the y coordinates. I think 1 good example will clear the problem up.

回答1:

Based on the first example of the doc, and given that the function you want to plot already exists in Racket, it's as simple as:

(require plot)
(plot (function sqr 0 5 #:label "y = x ^ 2"))

If you just want to see the individual points, this is also taken from the docs:

(require plot)
(define xs '(0 1 2 3 4 5))
(define ys '(0 1 4 9 16 25))
(plot (points (map vector xs ys) #:color 'red))

which is equivalent to

(require plot)
(plot (points '(#(0 0) #(1 1) #(2 4) #(3 9) #(4 16) #(5 25)) #:color 'red))