You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Plotly悬浮信息框中的线条与标记符号?

移除Plotly统一悬浮框中的线条与标记符号

针对这个问题,这里提供两种简单的解决方法:

方法1:清空轨迹名称

在plot_ly()的轨迹参数中添加name = "",统一悬浮框就不会显示对应轨迹的图例符号(线条+标记):

library(tidyverse)
library(plotly)

demand <- tibble(q = seq(0,100,by=2), wtp = 50 - q/2)

plot_ly(
    demand, x = ~q, y = ~wtp, 
    type = "scatter", mode = "lines+markers", 
    text = ~paste(wtp), hoverinfo = "text",
    name = ""
  ) |> 
  layout(hovermode = "y unified")

方法2:自定义悬浮模板

使用hovertemplate替代text和hoverinfo,直接定义悬浮框的显示内容,通过<extra></extra>标签隐藏默认的符号和名称:

library(tidyverse)
library(plotly)

demand <- tibble(q = seq(0,100,by=2), wtp = 50 - q/2)

plot_ly(
    demand, x = ~q, y = ~wtp, 
    type = "scatter", mode = "lines+markers", 
    hovertemplate = "%{y}<extra></extra>"
  ) |> 
  layout(hovermode = "y unified")

<extra></extra>的作用是清除悬浮框中默认附加的轨迹标识信息,只保留你指定的内容。

内容的提问来源于stack exchange,提问作者profj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 17:02:47