Код ниже содержит ссылку на википедию для функции
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 6 17:33:00 2019
@author: thomas
Ternary Plots,
compare: https://en.wikipedia.org/wiki/Ternary_plot
"""
import math
import matplotlib.pyplot as plt
import numpy as np
def cartesianCoord(tple):
a,b =tple
c=1-a-b #the sum of all ternary coords needs to be 1
assert (0 <= (a+b) <= 1 ), 'Sum of variables needs to be between 0 and 1'
return (1/2*(2*b+c)/(a+b+c), math.sqrt(3)/2*c/(a+b+c)) #see wikipedia
print(cartesianCoord((0.,0.)))
aa = np.linspace(0.0, 1.0, 11)
bb = np.linspace(0.0, 1.1, 12) #one step more (see line 30)
x=[]
y=[]
for i,a in enumerate(aa):
for b in bb[:-(i+1)]:
xx,yy = cartesianCoord((a,b))
x.append(xx)
y.append(yy)
plt.scatter(x,y) #scatter points for the coordination system grid
tlines = [((0.8, 0.0), (0.0, 0.7)), ((0.0, 0.2), (0.4, 0.4)), ((0.0, 0.0), (1.0, 0.0))] #ternary
for l in tlines:
a = cartesianCoord(l[0]) #start
e = cartesianCoord(l[1]) #end
x = [a[0], e[0]]
y = [a[1], e[1]]
plt.plot(x,y , color='red') #plot the lines in red
plt.show()