我想了解如何使用plotly正确绘制等高线图。在下面的代码中,我有 x、y、z,因此我使用 akima 包中的 interp 进行插值以获得更定义的范围。我首先使用plotly绘制结果,然后使用filled.contour绘制结果。绘图的结果是错误的,但我更喜欢它在填充轮廓中的美感,结果是正确的。
我在 plotly 上做错了什么?
require(akima)
require(plotly)
x = rand(15,1)
y = rand(15,1)
z = rand(15,1)
a = interp(x, y, z)
p = plot_ly(x = a$x,
y = a$y,
z = a$z,
type = "contour")
p
filled.contour(a$x,a$y,a$z)
最佳答案
Plotly 期望矩阵排列略有不同。这是一个修复:
require(akima)
require(plotly)
library(pracma)
set.seed(1)
x = rand(15,1)
y = rand(15,1)
z = rand(15,1)
a = interp(x, y, z)
plot_ly(x = a$x,
y = a$y,
z = matrix(a$z, nrow = length(a$y), byrow = TRUE),
type = "contour")
filled.contour(a$x,a$y,a$z)
没有矩阵重排:
plot_ly(x = a$x,
y = a$y,
z = a$z,
type = "contour")
关于r - Plotly 等高线图行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49426510/