如何使用SQLAlchemy / Mysql存储3D Graph(x,y,z)数据?

时间:2017-12-27 11:29:14

标签: python mysql python-3.x sqlalchemy mysql-python

我正在使用带有Flask的Python将3D图形的X,Y,Z值提供给Javascript(Plotly库)。数据如下所示:

z = [1,1,1,1,1,1,1,1,1,1,1,1];
x = [0.0100,0.0420,0.0500,0.0508,0.0769,0.0883,0.0900,0.1101,0.1256,0.1300,0.1385,0.1607];
y = [0.0131,0.0190,0.0248,0.0250,0.0310,0.0370,0.0384,0.0430,0.0490,0.0530,0.0550,0.0610];

所有这些都是针对1个3D图形,它看起来像这样: enter image description here

问题是,我的网站上会有很多3D图形,并且在代码中将所有这些图形存储在Python数组中是荒谬的。将所有这些坐标存储在数据库中最有效的方法是什么?感谢。

1 个答案:

答案 0 :(得分:1)

你可以使用PostgreSql数据库,它有ARRAY,所以,你可以创建一个表,包含哪些列:

id: integer
graph_name: text
xpoints: double precision[]
ypoints: double precision[]
zpoints: double precision[]

其中“double precision []”是8字节浮点数据类型的数组。

因此每个图表都会存储在表格的一行中。

对于数组列,您应该使用postgresql.ARRAY数据类型(在SqlAlchemy中)