散点图不会绘制数组+三元库中的所有点

时间:2018-01-30 08:02:42

标签: python pandas ternary

我在python中使用三元库并试图在三元图中绘制点的散点图。 但是,下面的代码似乎只为每个3次散布调用绘制了一个单点。 你能告诉我吗

    scale = 1
    figure, tax = ternary.figure(scale=scale)     
    tax.set_title("Scatter Plot", fontsize=20)          
    tax.boundary(linewidth=2.0)        
    tax.gridlines(multiple=5, color="blue")          
    # Plot a few different styles with a legend        
    points = np.array([df['73_prop']])        
    tax.scatter(points, marker='s', color='red', label="Outflows")      
    points = np.array([df['72_prop']])       
    tax.scatter(points, marker='D', color='green', label="HQLA")       
    points = np.array([df['74_prop']])        
    tax.scatter(points, marker='o', color='blue', label="Inflows")       
    tax.legend()       
    tax.ticks(axis='lbr', linewidth=1, multiple=5)     

    tax.show()      

这是我现在得到的情节

enter image description here

    In [213]:points 
    Out[213]: 
    array([[ 0.47426346,  0.50559869,  0.50368877, ...,  0.65636812,
     0.56024801,  0.49020411]])

P.S。我试图模仿其中的内容: https://github.com/marcharper/python-ternary#scatter-plots

我也试过使用某些for循环但没有帮助。

1 个答案:

答案 0 :(得分:0)

您的输入数据格式错误。您提供了一个flots列表,您需要提供一个浮动列表列表:[ [x1,y1] , [x2,y2], ...]

这有效:

import ternary
import numpy as np 

scale = 1
figure, tax = ternary.figure(scale=scale)     
tax.set_title("Scatter Plot", fontsize=20)          
tax.boundary(linewidth=2.0)        
tax.gridlines(multiple=5, color="blue")          

rnd = np.random.random(120)
points = [ [x*x, np.random.random(1) * np.random.random(1) * (1-x)] for x in rnd]
tax.scatter(points, marker='s', color='red', label="Outflows")    


rnd = np.random.random(120)

# [[x1,y1], [x2,y2], ..., [xn,yn]] 
points = [ [x*x, np.random.random(1) * np.random.random(1) * (1-x)] for x in rnd]
tax.scatter(points, marker='D', color='green', label="HQLA")       

rnd = np.random.random(120)
points = [ [x*x, np.random.random(1) * np.random.random(1) * (1-x)] for x in rnd]
tax.scatter(points, marker='o', color='blue', label="Inflows")       

tax.legend()       
tax.ticks(axis='lbr', linewidth=1, multiple=5)     

tax.show()  

enter image description here