我正在使用R编程语言。
下面是一个用Python(https://www.geeksforgeeks.org/3d-wireframe-plotting-in-python-using-matplotlib/)制作的透明线图:
# importing modules
from mpl_toolkits import mplot3d
import numpy
from matplotlib import pyplot
# assigning coordinates
a = numpy.linspace(-5, 5, 25)
b = numpy.linspace(-5, 5, 25)
x, y = numpy.meshgrid(a, b)
z = numpy.sin(numpy.sqrt(x**2 + y**2))
# creating the visualization
fig = pyplot.figure()
wf = pyplot.axes(projection ='3d')
wf.plot_wireframe(x, y, z, color ='green')
# displaying the visualization
wf.set_title('Example 2')
pyplot.show()
字符串
的数据
**我的问题:**我试图在R中为二维正态分布重新创建这种图
我知道如何在R中绘制一个规则的二维正态分布:
library(plotly)
library(MASS)
library(mvtnorm)
mu <- c(0, 0) # Mean
Sigma <- matrix(c(1, 0.8, 0.8, 1), nrow=2)
x <- seq(-3, 3, length.out = 100)
y <- seq(-3, 3, length.out = 100)
grid <- expand.grid(x=x, y=y)
z <- matrix(apply(grid, 1, function(x) dmvnorm(x, mean=mu, sigma=Sigma)), nrow=length(x), ncol=length(y))
plot_ly(x = x, y = y, z = z, type = "surface") %>%
add_trace(
type = "surface",
showscale = FALSE,
opacity = 0.5,
surfacecolor = matrix(rep(1, length(x) * length(y)), nrow=length(x), ncol=length(y)),
colorscale = list(c(0, 1), c("rgb(0,0,0)", "rgb(0,0,0)")),
lighting = list(ambient = 1, diffuse = 0, fresnel = 0, specular = 0, roughness = 1)
) %>%
layout(scene = list(xaxis = list(title = 'X1'),
yaxis = list(title = 'X2'),
zaxis = list(title = 'Density')))
型
的
但我不知道如何让这个图看起来像“透明丝网”风格。我能找到的最接近的东西是这样的:https://www.r-bloggers.com/2010/05/creating-surface-plots/
有人能告诉我怎么做吗?注意:情节不需要是3D的。2D或3D都可以。
谢谢你,谢谢
**编辑:**我认为这是可能的。
library(plotly)
# Creating the data
x <- seq(-5, 5, length.out = 50)
y <- seq(-5, 5, length.out = 50)
grid <- expand.grid(x = x, y = y)
R <- sqrt(grid$x^2 + grid$y^2)
z <- sin(R)
fig <- plot_ly(x = ~grid$x, y = ~grid$y, z = ~z, type = 'scatter3d', mode = 'lines',
line = list(color = '#0066FF', width = 2)) %>%
layout(title = "Wireframe Plot",
scene = list(xaxis = list(gridcolor = 'rgb(255, 255, 255)',
zerolinecolor = 'rgb(255, 255, 255)',
showbackground = TRUE,
backgroundcolor = 'rgb(230, 230,230)'),
yaxis = list(gridcolor = 'rgb(255, 255, 255)',
zerolinecolor = 'rgb(255, 255, 255)',
showbackground = TRUE,
backgroundcolor = 'rgb(230, 230,230)'),
zaxis = list(gridcolor = 'rgb(255, 255, 255)',
zerolinecolor = 'rgb(255, 255, 255)',
showbackground = TRUE,
backgroundcolor = 'rgb(230, 230,230)')),
showlegend = FALSE)
# Print
fig
型
1条答案
按热度按时间wgx48brx1#
点阵封装具有
wireframe()
函数(https://cran.r-project.org/web/packages/lattice/lattice.pdf),例如字符串
x1c 0d1x的数据
如果你使用更少的数据点,你可以更好地看到“线”:
型
的
下面是一个复制你的python示例的可能方法:
型
创建于2023-12-13使用reprex v2.0.2