来自 plotly 的三元图

Ternary plot from plotly

enter image description here

我想在三元图中添加线条(水平、垂直)以突出显示某些部分。 可以帮帮我吗?

三元图

代码如下:

fig = px.scatter_ternary(df,a=df.a, b =df.b, c=df.c, symbol=data_small.Time,
                         color = df.x, size_max = 'size', opacity = [1,1], title=s,
                        symbol_sequence = [1,0])
fig.update_layout({
'ternary':
    {'sum':1,
    'aaxis':{'title': ' a<br>', 'min': 0, 
             'linewidth':2, 'ticks':'outside',
             'tickmode':'array','tickvals':[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]},
    'baxis':{'title': '<br>b', 'min': 0, 
             'linewidth':2, 'ticks':'outside',
             'tickmode':'array','tickvals':[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]},
    'caxis':{'title': '<br>c', 'min': 0, 
             'linewidth':2, 'ticks':'outside',
             'tickmode':'array','tickvals':[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]}}})
fig.show()

我从来没有用过这种图表,但是由于official reference画了一个圆,我觉得可以画一条线,所以我定制了它。简而言之,就是px.scatter_ternary+go.Scatterternary的组合。我无法回答有关坐标的问题。

import plotly.express as px
import plotly.graph_objects as go

df = px.data.election()
fig = px.scatter_ternary(df, a="Joly", b="Coderre", c="Bergeron", hover_name="district",
    color="winner", size="total", size_max=15,
    color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"} )

fig.add_trace(
    go.Scatterternary(a=[0.1, 0.5],
                      b=[0.9, 0.5],
                      c=[0.1, 0.4],
                      mode='lines',
                      marker=dict(color='purple'),
                      line=dict(width=4),
                      showlegend=False)
)

fig.show()