pyecharts绘制3D图表 参数配置和说明 Grid3DOpts、Axis3DOpts为3D图标需要配置项 Grid3DOpts:三位坐标系配置项 class pyecharts.options.Grid3DOpts
class Grid3DOpts(
width: Numeric = 200,
height: Numeric = 100,
depth: Numeric = 80,
is_rotate: bool = False,
rotate_speed: Numeric = 10,
rotate_sensitivity: Numeric = 1,
)
Axis3DOpts: 三位坐标轴配置项
class Axis3DOpts(
data: Optional[Sequence] = None,
type_: Optional[str] = None,
name: Optional[str] = None,
name_gap: Numeric = 20,
min_: Union[str, Numeric, None] = None,
max_: Union[str, Numeric, None] = None,
splitnum: Optional[Numeric] = None,
interval: Optional[Numeric] = None,
margin: Numeric = 8,
textstyle_opts: Union[TextStyleOpts, dict, None] = None,
)
所有3D图表均拥有以下方法
def add(
series_name: str,
data: Sequence,
shading: Optional[str] = None,
itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None
label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(is_show=False),
xaxis3d_opts: Union[opts.Axis3DOpts, dict] = opts.Axis3DOpts(type_="category"),
yaxis3d_opts: Union[opts.Axis3DOpts, dict] = opts.Axis3DOpts(type_="category"),
zaxis3d_opts: Union[opts.Axis3DOpts, dict] = opts.Axis3DOpts(type_="value"),
grid3d_opts: Union[opts.Grid3DOpts, dict] = opts.Grid3DOpts(),
)
Example: 绘制3D柱状图 Bar3D
import random
from pyecharts import options as opts
from pyecharts.charts import Bar3D
from pyecharts.faker import Faker
data = [(i, j, random.randint(0, 12)) for i in range(6) for j in range(24)]
c = (
Bar3D()
.add(
"",
[[d[1], d[0], d[2]] for d in data],
xaxis3d_opts=opts.Axis3DOpts(Faker.clock, type_="category"),
yaxis3d_opts=opts.Axis3DOpts(Faker.week_en, type_="category"),
zaxis3d_opts=opts.Axis3DOpts(type_="value"),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(max_=20),
title_opts=opts.TitleOpts(title="Bar3D-基本示例"),
)
)
c.render_notebook()
需要说明一下pyecharts.fakter Faker数据集是Pyecharts自带的数据集.Pyecharts图标案例中使用的可视化数据来源都源于pyecharts中的faker.py文件. Lin3d:3D折线图
import math
import pyecharts.options as opts
from pyecharts.charts import Line3D
week_en = "Saturday Friday Thursday Wednesday Tuesday Monday Sunday".split()
clock = (
"12a 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12p "
"1p 2p 3p 4p 5p 6p 7p 8p 9p 10p 11p".split()
)
data = []
for t in range(0, 25000):
_t = t / 1000
x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)
y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)
z = _t + 2.0 * math.sin(75 * _t)
data.append([x, y, z])
c=(
Line3D()
.add(
"",
data,
xaxis3d_opts=opts.Axis3DOpts(data=clock, type_="value"),
yaxis3d_opts=opts.Axis3DOpts(data=week_en, type_="value"),
grid3d_opts=opts.Grid3DOpts(width=100, height=100, depth=100),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
dimension=2,
max_=30,
min_=0,
range_color=[
"#313695",
"#4575b4",
"#74add1",
"#abd9e9",
"#e0f3f8",
"#ffffbf",
"#fee090",
"#fdae61",
"#f46d43",
"#d73027",
"#a50026",
],
)
)
)
c.render_notebook()
3D图还包括 Surface3D:3D曲面图 Scatter3D:3D散点图 Map3D:三维地图等等 还有介绍pyecharts的全局配置项和系列配置项,可以完成一个完成的网页可视化展示 都在官网https://pyecharts.org/#/zh-cn/intro,有不懂的可以留言,或者更好的代码,欢迎大家一起讨论
|