Plotly Contour情节行为

时间:2018-03-22 10:39:06

标签: r plotly

我想了解如何正确地绘制等高线图。在下面的代码中我有x,y,z所以我插入以使用akima包中的interp具有更明确的范围。我先用plotly然后用filled.contour绘制结果。情节的结果是错误的,但我更喜欢它在填充轮廓中的美学,结果是正确的。

我在故事中做错了什么?

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)

1 个答案:

答案 0 :(得分:2)

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

enter image description here

filled.contour(a$x,a$y,a$z)

enter image description here

没有矩阵重排:

plot_ly(x = a$x,
        y = a$y,
        z = a$z,
        type = "contour")

enter image description here

相关问题