使用 Racket 绘制点 [英] Using Racket to Plot Points

查看:53
本文介绍了使用 Racket 绘制点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在花了一些时间查看文档、搜索网络并在提示下进行试验后,我没有成功地使用 Racket 绘制点.有人可以发布一个示例,说明我如何为我的 x 坐标绘制 (0 1 2 3 4 5) 和为 y 坐标绘制 (0 1 4 9 16 25).我认为 1 个很好的例子可以解决这个问题.

解决方案

基于 :

(需要绘图)(定义 xs '(0 1 2 3 4 5))(定义 ys '(0 1 4 9 16 25))(绘图(点(地图向量 xs ys)#:color 'red))

相当于

(需要绘图)(情节(点'(#(0 0)#(1 1)#(2 4)#(3 9)#(4 16)#(5 25))#:颜色'红色))

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.

解决方案

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

这篇关于使用 Racket 绘制点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆