gpt4 book ai didi

r - R中的曲线和绘图函数有什么区别?

转载 作者:行者123 更新时间:2023-12-04 12:50:34 25 4
gpt4 key购买 nike

f1<-function(t)
{
sqrt((t^2)+1)
}

curve(f1,from=0,to = 5,n=10)
plot(f1,from=0,to = 5,n=10)

给出相同的输出。那么,曲线和绘图函数有什么区别呢?

最佳答案

功能不多。 plot最终调用 curve .
plot是一个通用函数,这意味着它有多种方法,具体取决于传递给它的对象类(在本例中为函数)。要找出特定方法背后的代码,您可以输入 graphcs:::plot.<method> .

在这种情况下,您可以看到 plot当应用于函数时,首先检查并调整其参数,然后最终才调用 curve .

> graphics:::plot.function
function (x, y = 0, to = 1, from = y, xlim = NULL, ylab = NULL,
...)
{
if (!missing(y) && missing(from))
from <- y
if (is.null(xlim)) {
if (is.null(from))
from <- 0
}
else {
if (missing(from))
from <- xlim[1L]
if (missing(to))
to <- xlim[2L]
}
if (is.null(ylab)) {
sx <- substitute(x)
ylab <- if (mode(x) != "name")
deparse(sx)[1L]
else {
xname <- list(...)[["xname"]]
if (is.null(xname))
xname <- "x"
paste0(sx, "(", xname, ")")
}
}
curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,
...)
}

关于r - R中的曲线和绘图函数有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52107192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com