在 Plotly 的单个跟踪中显示多个图例 [英] Displaying multiple legends in a single trace in Plotly

查看:169
本文介绍了在 Plotly 的单个跟踪中显示多个图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以 docs 几乎使它看起来像是为相同的不同项目显示多个图例trace (plotly.graph_objs.Scatter) 不是 Plotly 默认支持的东西.您应该继续向 Figure 中添加新的轨迹,并且这些轨迹中的每一个都包含自己的图例.

So the docs pretty much make it look like displaying multiple legends for different items of the same trace (plotly.graph_objs.Scatter) isn't something that Plotly supports by default. You should rather keep adding new traces to Figure and each of these traces contains its own legend.

但是,对于我的具体情况,这似乎很麻烦.我拥有的是 Plotly Dash 中的图表,用户可以在其中搜索不同的节点 &路径,所以我根据搜索和所有这些在单个跟踪中定义不同的颜色(通过使用 colorscale 和来自 Scatter 的颜色.

However, this seems cumbersome for my specific case. What I have is a graph in Plotly Dash where the user can search for different nodes & paths and so I am defining different colors according to the search and all of this within a single trace (by making use of colorscale & color from Scatter).

当用户在图中搜索不同的节点时,我会对它们进行独特的着色.我想为突出显示这些节点的每种不同颜色专门显示一个图例.

When a user searches for different nodes in the graph I am coloring them uniquely. I'd like to specifically show a legend for each of the different colors which highlight these nodes.

是否可以在单个跟踪中完成此操作?

Is it possible to do this in a single trace?

推荐答案

目前这是不可能的.docs 中没有这样的例子,尽管有一个 issue 关于这个话题几年了.

Currently this is not possible. There is no such example in the docs though there is an issue on this topic since a couple of years now.

这篇关于在 Plotly 的单个跟踪中显示多个图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆