plotly - Plot.ly - 图例中同一键的多条轨迹

标签 plotly

我一直在使用 plot.ly 并希望将多个跟踪分组到图例中的同一个键。
我有显示有关特定用户的数据的子图。我想让每个键代表一个用户,而不是 user.data1、user.data2 等。

这是我现在所拥有的一个例子:



我想将所有 1 分组到他们自己的 key 中,所有 2 分组到他们自己的 key 中,所有 3 分组到他们自己的 key 中。

我的代码的这一部分展示了我目前如何进行跟踪

trace1_A = go.Scatter(x=file1.a, y=file1.b, name='1') #plot1
trace1_B = go.Scatter(x=file1.c, y=file1.d, name='1') #plot2
trace1_C = go.Scatter(x=file1.e, y=file1.f, name='1') #plot3
trace1_D = go.Scatter(x=file1.g, y=file1.h, name='1') #plot4

最佳答案

这是我的解决方案的最终 View ,添加 legendgroupmarker=dict(color='') 以及 showlegend 使我达到了预期的结果。

trace1_A = go.Scatter(x=file1.a, y=file1.b, name='1', legendgroup='1', marker=dict(color='red'))
trace1_B = go.Scatter(x=file1.c, y=file1.d, name='1', legendgroup='1', marker=dict(color='red'), showlegend=False)
trace1_C = go.Scatter(x=file1.e, y=file1.f, name='1', legendgroup='1', marker=dict(color='red'), showlegend=False)
trace1_D = go.Scatter(x=file1.g, y=file1.h, name='1', legendgroup='1', marker=dict(color='red'), showlegend=False)
trace2_A = go.Scatter(x=file2.a, y=file2.b, name='2', legendgroup='2', marker=dict(color='blue'))
trace2_B = go.Scatter(x=file2.c, y=file2.d, name='2', legendgroup='2', marker=dict(color='blue'), showlegend=False)
trace2_C = go.Scatter(x=file2.e, y=file2.f, name='2', legendgroup='2', marker=dict(color='blue'), showlegend=False)
trace2_D = go.Scatter(x=file2.g, y=file2.h, name='2', legendgroup='2', marker=dict(color='blue'), showlegend=False)
trace3_A = go.Scatter(x=file3.a, y=file3.b, name='3', legendgroup='3', marker=dict(color='green'))
trace3_B = go.Scatter(x=file3.c, y=file3.d, name='3', legendgroup='3', marker=dict(color='green'), showlegend=False)
trace3_C = go.Scatter(x=file3.e, y=file3.f, name='3', legendgroup='3', marker=dict(color='green'), showlegend=False)
trace3_D = go.Scatter(x=file3.g, y=file3.h, name='3', legendgroup='3', marker=dict(color='green'), showlegend=False)

关于plotly - Plot.ly - 图例中同一键的多条轨迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56533910/

相关文章:

javascript - 使用选项卡时调整图表高度大小

python - 如何将 Plotly 中的 Y 轴从科学轴更改为指数轴或普通轴?

python - 使用 Python 在 Plotly 中分组图例

python - 如何在 python 中使用 plotly 删除条形图中的间隙

r - 如何在 Plotly 中移动轴名称?

python - 如何使用 plotly figure_factory 仅绘制散点图矩阵的下半部分?

python - 如何切换 3D 散点图中的 Axis 方向?

docker - Grafana:通过 docker-compose 添加 Plotly 插件

python - Plotly python 直方图将自定义颜色添加到不同的值

javascript - 时间模式下的 Plot.ly : fixed grid size