gpt4 book ai didi

r - 使用Plotly在等高线图上叠加线

转载 作者:行者123 更新时间:2023-12-04 22:04:40 24 4
gpt4 key购买 nike

我想在Plotly等高线图上覆盖一条线,类似于在矩阵图像上覆盖一条线,其中强度表示zR3中的位置:

# Generate an arbitrary matrix
m <- matrix(sin(1:6^2) * 1:6, nrow = 6)

# Define a path
path <- data.frame(x = c(0:7), y = c(0, 1, 2, 2, 3, 3, 4, 6))

image(x = 1:6, y = 1:6, z = m, col = gray.colors(20), xlab = "x", ylab = "y")
lines(path$x, path$y)

呈现:

Line and matrix plot

我尝试使用Plotly
library(plotly)
plot_ly(x = 1:6, y = 1:6, z = t(m), type = "contour") %>%
add_lines(x = path$x, y = path$y)

生成轮廓图,该轮廓图用空 R3空间而不是直线的线框覆盖:

enter image description here

最佳答案

您可以尝试以下方法:

plot_ly(x = 1:6, y = 1:6, z = t(m), type = "contour") %>% 
add_trace(x = c(1, 2, 3, 4, 5, 6), y = c(1, 2, 3, 3, 4, 5), type = "scatter", mode = "line")

它几乎为您提供所需的东西。希望能帮助到你!

enter image description here

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com