Skip to main content
 首页 » 编程设计

python之如何使用 Python Plotly 制作三元等高线图

2024年12月31日9lovecherry

我正在尝试绘制在单纯形上定义的函数。显然,你可以 do it very nicely using the Matlab API .

但我不知道如何使用 Python API 执行此操作。该引用有一个名为 Ternary Contour Plots in Python 的部分但它不绘制数值函数,而是将单纯形映射到给定离散集的函数。

我尝试模拟 Matlab 代码:

import plotly as py 
 
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] 
 
trace = { 
    "type": 'scatterternary', 
    "carpet": 'scattercontour', 
    "a": A, 
    "b": B, 
    "c": C, 
    "z": Z 
} 
 
layout = { 
    'title': 'Simple Ternary Contour Plot with Python' 
} 
 
figure = dict(data=[trace], layout=layout) 
py.offline.plot(figure, validate=False) 

但我得到的是这个 plotly :

请您参考如下方法:

如果还有人感兴趣,here是一个 Jupyter Notebook,用于查看如何生成 Plotly 三元等高线图。