How to avoid duplicate legend labels in plotly or pass custom legend labels(如何避免重复的图例标签或通过自定义图例标签)
问题描述
如何避免子图中重复的图例标签?我在 matplotlib 中进行此操作的一种方法是将自定义图例标签传递给图例对象.我在 plotly 中找不到任何等效选项的文档.有任何想法吗?
How can I avoid duplicate legend labels in subplots? One way I would go about it in matplotlib would be to pass custom legend labels to an legend object. I couldn't find any documentation for an equivalent option in plotly. Any ideas?
推荐答案
Plotly 在跟踪级别控制这个.尝试在您不想出现在图例中的 Histogram
跟踪中传入 showlegend=False
.
Plotly controls this on the trace level. Try passing in showlegend=False
inside the Histogram
traces that you don't want to appear in the legend.
参考:https://plot.ly/python/reference/#Histogram-showlegend
示例:https://plot.ly/python/legend/#Hiding-图例条目
从上面的链接直接复制粘贴.
Direct copy-paste from the link above.
你想看到的用法在上面的trace1
中.
The usage you want to see is shown in trace1
above.
这篇关于如何避免重复的图例标签或通过自定义图例标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!