Titles in colorbars in ternary contour plot


I have been using plotly to generate a ternary contour plot using the create_ternary_contour function. Everything works fine and I can get the plot that I want. However, I would like to add a title to the colorbar that is displayed. I could not do it directly from create_ternary_contour as it does not have the option to modify the colorbar via a dictionary like a figure from graph_objects.
Is there a way to add a title or modify the colorbar at all when using figures from the figure_factory class?



Hi @jchico,

A simple figure, containing a ternary contour, consists in many traces of type Scatterternary (just print(len(fig.data)) to find out their number). To identify which one has an attribute marker_colorscale, to set also the marker_colorbar_title, use fig.update_traces with selector, to select the right trace to be updated.


import plotly.figure_factory as ff
import numpy as np
Al = np.array([0. , 0. , 0., 0., 1./3, 1./3, 1./3, 2./3, 2./3, 1.])
Cu = np.array([0., 1./3, 2./3, 1., 0., 1./3, 2./3, 0., 1./3, 0.])
Y = 1 - Al - Cu

enthalpy = 2.e6 * (Al - 0.01) * Cu * (Al - 0.52) * (Cu - 0.48) * (Y - 1)**2 - 5000
fig = ff.create_ternary_contour(np.array([Al, Y, Cu]), enthalpy,
                                pole_labels=['Al', 'Y', 'Cu'],
                                title='Mixing enthalpy of ternary alloy')

fig.update_traces(marker_colorbar_title='mytitle', selector=dict(marker_showscale=True))

The last line is settting the marker_colorbar_title='mytitle into the trace definition that contains marker_showscale=True. (search for selector in this page https://plotly.com/python/creating-and-updating-figures/ to see more examples of using selector)

1 Like

Thank you! That worked like a charm