I am using the ternary library in python and trying to plot a scatter of points in the ternary plot. However it appears the below code only plots one single point for each of the 3 scatter calls made. Can you please advise
我在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()
Here is the plot i get right now
这是我现在得到的情节
In [213]:points
Out[213]:
array([[ 0.47426346, 0.50559869, 0.50368877, ..., 0.65636812,
0.56024801, 0.49020411]])
P.S. Am trying to mimic what's there on: https://github.com/marcharper/python-ternary#scatter-plots
附:我试图模仿那里有什么:https://github.com/marcharper/python-ternary#scatter-plots
I have also tried using certain for loop but hasn't helped.
我也试过使用某些for循环,但没有帮助。
1 个解决方案
#1
0
Your input data has the wrong format. You supply a list of flots, you need to supply a list of list of floats: [ [x1,y1] , [x2,y2], ...]
您的输入数据格式错误。你提供了一个flots列表,你需要提供一个浮动列表列表:[[x1,y1],[x2,y2],...]
This works:
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()
#1
0
Your input data has the wrong format. You supply a list of flots, you need to supply a list of list of floats: [ [x1,y1] , [x2,y2], ...]
您的输入数据格式错误。你提供了一个flots列表,你需要提供一个浮动列表列表:[[x1,y1],[x2,y2],...]
This works:
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()