Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

How to use Ternary Contour Plots

I have datas in a triangle, and I want to use Ternary Contour plot. But I do not know how to do it.

The examples do now show the information on the datas. Could somebody explain it more, or give an example?

Thank you very much!

Hi @leiniu,

The basic idea in is that for each region is represented by a ternary trace with fill='toself'. The trace specifies the outline of the region on the plot, and the fill option causes the region to be filled in with the trace’s line color.

You can take a look at the raw data for the example at

Hope that helps get you started!

Hi! Thank you very much for your reply. It is indeed helpful.

Is it possible to create ternary contour plot in plotly with python as shown in the following figure:

The original question appeared in

Thank you very much!

Hi @leiniu,

There’s not single trace the will produce this plot. I think it should be possible, but It would take a bit of work. The general approach I’d recommend:


Thanks again. I found that there is a method for plotly with matlab as shown in the following:

To make this plot, you'll need the the Ternplot package
from the MATLAB [File exchange]( % add data % An + Bn + Cn = 1 % Z controls contour A = [0 .2 .2 .2 0 .6 .75 .9 0 1 .8 .3]; B = [1 .2 .4 .1 0 .4 .05 0 .8 0 .05 .3]; C = [0 .6 .4 .7 1 0 .2 .1 .2 0 .15 .4]; Z = [.1 .5 .1 .2 1 .8 .4 0 .1 .6 1 .7]; % create figure fig = figure; terncontour(A, B, C, Z) ternlabel('A', 'B', 'C') % Plotly pf = fig2plotly(fig, 'strip', false, 'filename', 'YOUR_FILENAME'); % Edit the contour fill and color in Plotly's online editor

Is it possible for plotly with python is such a simple way?

Hi @leiniu,

I don’t think there’s a simple way to build this plot in python directly.


Hi. There is a guide for Ternary Contour Plot with python as shown in the following figure

I think this is an interesting example. Do you know how to find the reference for this plot? Thank you very much again.

This the webpage for Plotly with Python:

Thanks a good question @leiniu, I don’t know how that example was created.

@chriddyp, @chelsea, or @etienne do you remember how this thumbnail image for the “Ternary Contour Plots” (See post above) was created?


@leiniu, @jmmease,
Here is a workaround for ternary contour plot:

and two contour plots:,

1 Like

Hi, @empet. Many thanks for your interesting and inspiring example. I really appreciate them.

By the way, when I try to run the code in your example, I found that the sides of the triangle are jagged. So I plot an additional trace defined bellow:
trace0 = go.Scatter(
line=dict(width=5, color=‘white’),
Then I plot this trace and the contour trace together. The sides of the triangle seem to be smooth. Is there any other regular way to smooth the boundary of the triangle?

Thank you again!

Hi @jmmease. @empet provides a possible way to create Ternary Contour Plot with python above. Thank you for your help.

Hi @leiniu, The triangle sides are jagged because of the rectangular meshgrid. A larger number, N, of grid points in both directions, can smooth the sides. Your solution to plot the side lines fixes this issue.