双轴三元系。从x到y的投影,f(x)

2024-10-01 13:38:51 发布

您现在位置:Python中文网/ 问答频道 /正文

Wanted result. Partially manually generated in Geogebra

如何生成两个60度的轴(x,y),从x到y有一条直线,y点是通过函数f(x)生成的?你知道吗

例如,如果轴可以放在“层”中,层可以倾斜到任何所需的角度,而平行于轴的光线被生成以形成非交互网格(类似于我在Geogebra中所做的),这将是非常好的,尽管如果它可以交互(就像在Geo中所做的那样)也不会造成伤害。手动添加交点时(如图所示)。你知道吗

我是个笨蛋,发发发慈悲吧。你知道吗

顺便说一句,我对轴的数量或它们的相对位置没有限制。我意识到第三组平行光线也必须产生才能得到图片,但是“层”根本不必是交互的,因为所有的交点都是通过另外两个获得的。你知道吗


Tags: 函数网格数量图片手动直线geo笨蛋
1条回答
网友
1楼 · 发布于 2024-10-01 13:38:51

下面的代码包含该函数的wikipedia链接

    #!/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()

相关问题 更多 >