多元图中的R层颜色
我们如何制作不同的颜色层,以便更好地看到R中的多元函数?我想检查函数是否是拟凹和拟凸的,但这些东西很难在单色图中看到多元图中的R层颜色,r,charts,colors,R,Charts,Colors,我们如何制作不同的颜色层,以便更好地看到R中的多元函数?我想检查函数是否是拟凹和拟凸的,但这些东西很难在单色图中看到 # Define Sequences for Multivariate Function xf3x1 <- seq(-100, 100, length=500) xf3x2 <- seq(-100, 100, length=500) # Outer Calculates the Cartesian Product z <- outer(xf3x1,xf3x2,
# Define Sequences for Multivariate Function
xf3x1 <- seq(-100, 100, length=500)
xf3x2 <- seq(-100, 100, length=500)
# Outer Calculates the Cartesian Product
z <- outer(xf3x1,xf3x2,function(xf3x1,xf3x2) xf3x1*xf3x2)
persp(xf3x1,xf3x2,z,col="lightgreen",theta=30,phi=20, main="Problème 3: Function 3")
定义多元函数的序列
xf3x1首先,需要设置
border=NA
以关闭曲面面周围的边界
一种方法是基于z值进行着色。改编:
绘图3D软件包是一个附加选项<代码>persp3D默认情况下按z值显示颜色:
library(plot3D) # For persp3D function
# Define Sequences for Multivariate Function
#### length=50 to speed up plotting ####
xf3x1 <- seq(-100, 100, length=50)
xf3x2 <- seq(-100, 100, length=50)
# Outer Calculates the Cartesian Product
z <- outer(xf3x1,xf3x2,function(xf3x1,xf3x2) xf3x1*xf3x2)
persp(xf3x1,xf3x2, z, theta=30, phi=20,
col="lightgreen",
main="persp: Black border lines overwhelm plot")
persp(xf3x1,xf3x2, z, theta=30, phi=20,
col="lightgreen",
border="black", lwd=0.2, # Or border=NA per @jlhoward
main="persp: Thinner border lines")
persp3D(xf3x1,xf3x2, z, theta=30, phi=20,
main="persp3D: No borders by default")
persp3D(xf3x1,xf3x2, z, theta=30, phi=20,
border="black", lwd=0.5,
main="persp3D with borders")
library(plot3D)#用于persp3D函数
#定义多元函数的序列
####长度=50以加快打印速度####
xf3x1
zlen <- diff(range(z)) + 1
clrs <- rev(rainbow(zlen))
col <- clrs[ z - min(z) + 1 ] # assign colors to heights for each point
open3d(scale=c(100,100,1))
surface3d(xf3x1,xf3x2,z,col=col, main="Problème 3: Function 3")
axes3d(box=TRUE)
title3d(xlab="xf3f1", ylab="xf3x2", zlab="z")
library(plot3D) # For persp3D function
# Define Sequences for Multivariate Function
#### length=50 to speed up plotting ####
xf3x1 <- seq(-100, 100, length=50)
xf3x2 <- seq(-100, 100, length=50)
# Outer Calculates the Cartesian Product
z <- outer(xf3x1,xf3x2,function(xf3x1,xf3x2) xf3x1*xf3x2)
persp(xf3x1,xf3x2, z, theta=30, phi=20,
col="lightgreen",
main="persp: Black border lines overwhelm plot")
persp(xf3x1,xf3x2, z, theta=30, phi=20,
col="lightgreen",
border="black", lwd=0.2, # Or border=NA per @jlhoward
main="persp: Thinner border lines")
persp3D(xf3x1,xf3x2, z, theta=30, phi=20,
main="persp3D: No borders by default")
persp3D(xf3x1,xf3x2, z, theta=30, phi=20,
border="black", lwd=0.5,
main="persp3D with borders")