Using Racket to Plot Points

2019-08-05 05:30发布

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条回答
走好不送
2楼-- · 2019-08-05 05:50

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"))

enter image description here

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))

enter image description here

查看更多
登录 后发表回答