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

Plotly中如何使用图片或图标替代散点图的默认彩色标记点?

问题原因

你使用的type: 'image'是全局图片trace类型,作用是将单张图片渲染到整个图表画布,所以会出现整张图被单张图片覆盖的问题。要实现每个散点显示指定摩天轮图标,使用普通scatter类型的自定义标记能力即可。

方案1:用emoji直接实现(无需额外准备图标资源)

直接用摩天轮emoji作为散点的文本标记,实现成本最低:

const x = Array.from({ length: 500 }, () => Math.random() * (6 - 3) + 3);
const y = Array.from({ length: 500 }, () => Math.random() * (6 - 3) + 3);

const data = [{
    x,
    y,
    type: 'scatter',
    mode: 'text',
    text: '🎡',
    textfont: {
        // 可根据需求调整emoji显示大小
        size: 16
    },
    name: '摩天轮点位',
    showlegend: true
}];

Plotly.newPlot('chart', data);
方案2:用自定义图片作为标记

如果需要使用特定设计的摩天轮图片,可以通过marker.symbol配置自定义图片资源:

const x = Array.from({ length: 500 }, () => Math.random() * (6 - 3) + 3);
const y = Array.from({ length: 500 }, () => Math.random() * (6 - 3) + 3);

// 替换为你的摩天轮图片本地路径/base64资源地址
const ferrisWheelIcon = '你的摩天轮图标资源地址';

const data = [{
    x,
    y,
    type: 'scatter',
    mode: 'markers',
    marker: {
        symbol: `url(${ferrisWheelIcon})`,
        // 可根据图片尺寸调整显示大小
        size: 20
    },
    name: '摩天轮点位',
    showlegend: true
}];

Plotly.newPlot('chart', data);

注意:自定义图片需要满足同源策略,否则会出现跨域无法渲染的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 08:24:02