r - Plotly 等高线图行为

标签 r plotly

我想了解如何使用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")

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

关于r - Plotly 等高线图行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49426510/

相关文章:

r - 是否有与值 = TRUE 的 grep 等效的字符串?

r 循环中的 dbWriteTable

r - 从 sqldf 查询调用 R 函数

python - Plotly:如何设置文本格式(下划线、粗体、斜体)

python - Plotly-Dash : Want two stacked bar charts side by side from single df column

r - 更改绘图图表中的图例大小

javascript - 如何在plotly.js 的堆积面积图中显示值和名称?

r - R 中 group_by、mutate 和 summarize 的排序

r - 如何在嵌套的 lapply/sapply 函数中附加值?

python - 有没有办法开始使用 plotly 在特定区域上缩放的绘图?