1、摘要
本文主要讲解:使用python中的pyecharts画三维折线图 主要思路:
- 将数据处理成[[x…],[y…],[z…]]的形式
- 使用Line3D函数渲染
2、数据介绍
数据为简单的三维数据 下图三维数据链接
3、相关技术
pyecharts是一款将python与echarts结合的强大的数据可视化工具 Line3D制作三维折线图
4、完整代码和步骤
代码输出如下:
主运行程序入口
import pyecharts.options as opts
from pyecharts.charts import Line3D
import csv
src = 'D:\document\\\'
file = '1.csv'
def readCsv(filepath):
encoding = 'gbk'
birth_data = []
try:
with open(filepath, 'r', encoding=encoding) as csvfile:
csv_reader = csv.reader(csvfile)
for row in csv_reader:
birth_data.append(row)
csvfile.close()
return birth_data
except:
with open(filepath, 'r', encoding='utf-8') as csvfile:
csv_reader = csv.reader(csvfile)
for row in csv_reader:
birth_data.append(row)
csvfile.close()
return birth_data
def readXYZfile():
XYZ = readCsv(src + file)
data = []
for index in range(350, 400):
for n in range(0, len(XYZ[index])):
data0 = index
data1 = n
height = float(XYZ[index][n])
if height < -9999:
data2 = -1000
else:
data2 = height
point = [data0, data1, data2]
data.append(point)
return data
data = readXYZfile()
print(data)
c = (
Line3D(init_opts=opts.InitOpts(width="1800px", height="800px"))
.add(
series_name="",
shading="color",
data=data,
xaxis3d_opts=opts.Axis3DOpts(type_="value"),
yaxis3d_opts=opts.Axis3DOpts(type_="value"),
grid3d_opts=opts.Grid3DOpts(width=200, height=50, depth=100),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
dimension=2,
max_=0,
min_=-780,
range_color=[
"#313695",
"#74add1",
"#e0f3f8",
"#fee090",
"#f46d43",
"#a50026",
],
)
)
.render("——350-400.html")
)
5、学习链接
可视化例子(11)——ECharts line3D制作三维折线图
|