pyecharts--3D散点图
程序员文章站
2024-03-22 16:52:58
...
data中行表示一个人到达h1,h2,h3的时间(时间戳)
做一个3D散点图,希望能从图上看出哪些人可能是团体,哪些人是单独行动。
from pyecharts import options as opts
from pyecharts.charts import Scatter3D
data = [[2675029, 2751842, 2924585],
[2672022, 2751718, 2924840],
[2653937, 2751696, 2924810],
[2675051, 2751850, 2924585],
[2675251, 2751798, 2924422],
[2675320, 2751733, 2924771],
[2654367, 2751747, 2924650],
[2653132, 2755289, 3015796],
[2675358, 2751667, 2924703],
[2653902, 2751689, 2924810],
[2675237, 2751814, 2924422],
[2671985, 2751753, 2924741],
[2653467, 2751821, 2924532],
[2654382, 2751739, 2924650],
[2675337, 2751726, 2924771],
[2653062, 2751835, 2924381],
[2653041, 2751827, 2924381],
[2675291, 2751636, 2924468],
[2672011, 2751775, 2924741],
[2654013, 2755282, 3015866],
[2675385, 2751653, 2924703],
[2653993, 2755523, 3015898],
[2653450, 2751859, 2924532],
[2654403, 2751675, 2924494],
[2675372, 2751659, 2924703],
[2653967, 2755531, 3015898],
[2653159, 2755232, 3015772],
[2660208, 2751787, 2924616],
[2653108, 2755296, 3015772],
[2672036, 2751707, 2924840],
[2675110, 2755545, 3016063],
[2660227, 2751682, 2924616],
[2653493, 2755598, 3015960],
[2674999, 2755313, 3015840],
[2675132, 2755538, 3016063],
[2674973, 2755303, 3015840]]
scatter3D = (Scatter3D()
.add("", data,
# xaxis3d_opts=opts.Axis3DOpts(name='h1',name_gap=35,min_=2650000,max_=2680000,
# textstyle_opts=opts.TextStyleOpts(color='green',font_size=20,font_family='Times New Roman'),
# ),
# yaxis3d_opts=opts.Axis3DOpts(name='h2',name_gap=35,min_=2750000,max_=2760000,
# textstyle_opts=opts.TextStyleOpts(color='red',font_size=20,font_family='Times New Roman'),
# ),
# zaxis3d_opts=opts.Axis3DOpts(name='h3',name_gap=35,min_=2920000,max_=3020000,
# textstyle_opts=opts.TextStyleOpts(color='blue',font_size=20,font_family='Times New Roman'),
# ),
xaxis3d_opts=opts.AxisOpts(name='h1',name_gap=35,min_=2650000,max_=2680000,
splitline_opts=opts.AxisLineOpts(is_show=True),
name_textstyle_opts=opts.TextStyleOpts(color='green',font_size=20,font_family='Times New Roman'),
axislabel_opts=opts.LabelOpts(color='green',font_size=14,font_family='Times New Roman'),
),
yaxis3d_opts=opts.AxisOpts(name='h2',name_gap=35,min_=2750000,max_=2760000,
splitline_opts=opts.AxisLineOpts(is_show=True),
name_textstyle_opts=opts.TextStyleOpts(color='red',font_size=20,font_family='Times New Roman'),
axislabel_opts=opts.LabelOpts(color='red',font_size=14,font_family='Times New Roman'),
),
zaxis3d_opts=opts.AxisOpts(name='h3',name_gap=35,min_=2920000,max_=3020000,
splitline_opts=opts.AxisLineOpts(is_show=True),
name_textstyle_opts=opts.TextStyleOpts(color='blue',font_size=20,font_family='Times New Roman'),
axislabel_opts=opts.LabelOpts(color='blue',font_size=14,font_family='Times New Roman',margin=5),
),
grid3d_opts=opts.Grid3DOpts(is_rotate=True,rotate_speed=25),
)
.set_global_opts(
title_opts=opts.TitleOpts("Scatter3D-基本示例"),
visualmap_opts=opts.VisualMapOpts(is_show=False),
toolbox_opts=opts.ToolboxOpts(is_show=True),
)
)
scatter3D.render_notebook()
结果如下:
另有pyecharts官方文档
pyecharts 的详细配置项.
改进:
- 想要缩小图中点的大小,点太大导致两个点重叠在一起,像是一个点。(貌似是symbol_size,但是要怎么用鸭~唉)
- 点的标签,data共36个点,能否在散点图中标注点的顺序。