Issue with Changing Colors in Ternary Diagram in Plotly and Modifying Interactive Tooltip

Hello, I’m using the Plotly library in Python, specifically the figure_factory module and the create_ternary_contour function, to create a ternary contour diagram. I’d like to customize the color scale of the diagram, but so far, I’ve only been able to use the default color scales provided by the function.

When I try to change the colors in the ternary diagram, I’ve found that create_ternary_contour seems limited to using only default color scales. My question is whether anyone knows a way to define a custom color scale for this function or if there’s an alternative method to modify it.

Environment:

Python 3.9
Plotly 5.15.0 (please replace if you’re using a different version)
Operating System: Windows 10
import plotly.figure_factory as ff
import numpy as np

# Sample data setu
A =  [0.1, 0.2, 0.7]
B =  [0.6, 0.2, 0.1]
C =  [0.3, 0.6, 0.2]
Value =  np.array([1, 2, 3])


fig = ff.create_ternary_contour(np.array([A, B, C]), Value,
                                colorscale='YlGnBu',
)

fig.update_layout(
    title="Ternary Diagram with Custom Colors"
)
fig.show()

What I’ve Tried:

  1. I searched the documentation and forums but couldn’t find a solution to define a custom color scale.
  2. I attempted using methods like update_traces and colorscale, but they don’t seem to affect this type of plot.

Additional Question:
Along with the color issue, does anyone know how to modify the interactive tooltip that appears when hovering over points in the ternary diagram? I would like to customize the content or format of this tooltip.

Thanks in advance for any help or suggestions!

@Septases Your code works with 'YlGnBu':


I have a different Plotly version, 5.24.0, but it doesn’t matter, because since the initial definition of ff.create_ternary_contour, in 2021, it always worked with any colorscale in this list:

PLOTLY_SCALES=['Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis', 'Cividis']

and the code for ff.create_ternary_contour is unchanged
See https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/plotly/figure_factory/_ternary_contour.py#L241.

update: to answer your second question I searched the forum for this answer:
https://community.plotly.com/t/latexify-ternary-countour-plot-colobar/64470/6. It illustrates how difficult is to update a ternary_contour because such a figure with n contours contains n+3 traces, as it is explained at the above link. If you understand that explanation, then you can try to update correspondigly the n traces with new tooltips.

Thank you for your response.

So, for example, if I want to use a custom color because these color scales don’t work for me, I can’t do it? If that’s the case, it should be suggested for a future update since the color palettes seem outdated.

Thank you very much for your time; your responses have been very helpful in clarifying my issue.