How to add a polygon and a caption for it on a Ternary Plot?

Hi,
I’m using the first example from

#The code
import plotly.express as px
df = px.data.election()
fig = px.scatter_ternary(df, a=“Joly”, b=“Coderre”, c=“Bergeron”)
fig.show()

Is there a way to add a shaded area on the plot? For example, something like this:

Shaded area

t = [0.0, 0.0, 0.1, 0.2, 0.2]
l = [0.0, 0.3, 0.3, 0.2, 0.0]
r = [1.0, 0.7, 0.6, 0.6, 0.8]

then plot it somehow

… do something

and then add a caption for the shaded area at a certain position

… probably something like text(0.2, 0.1, 0.7, ‘The Caption’, ha=‘center’, va=‘center’)

Thank you for your help,
-Kari

Hey @karilint,

you can add another scatter_ternary and fill the space in between the lines with fill="toself"to achieve what you want. You can then use hoverinfo or text on that “shape” as you normally would. For example:

import plotly.express as px
import plotly.graph_objects as go
df = px.data.election()

t = [0.0, 0.0, 0.1, 0.2, 0.2]
l = [0.0, 0.3, 0.3, 0.2, 0.0]
r = [1.0, 0.7, 0.6, 0.6, 0.8]

fig = px.scatter_ternary(df, a="Joly", b="Coderre", c="Bergeron")
fig.add_scatterternary(a=t, b=l, c=r, name="shaded area",
                        mode='lines', fill="toself", text="throwing some shade", showlegend=False)


fig.show()

image

hope that helps

Hi @surchs,

thank you for your swift answer. This helped me a lot!
-Kari