【PyEcharts】中秋节快乐

用 PyEcharts 画个球面的参数方程

{ x = cos ⁡ ( t ) sin ⁡ ( s ) y = sin ⁡ ( t ) sin ⁡ ( s ) z = cos ⁡ ( s ) , t ∈ [ 0 , 2 π ] , s ∈ [ 0 , π ] \left\{\begin{aligned} &x=\cos(t)\sin(s)\\ &y=\sin(t)\sin(s)\\ &z=\cos(s)\\ \end{aligned}, t\in [0,2\pi],s\in [0,\pi]\right. x=cos(t)sin(s)y=sin(t)sin(s)z=cos(s),t[0,2π],s[0,π]

import math
from typing import Union

import pyecharts.options as opts
from pyecharts.charts import Surface3D



def float_range(start: int, end: int, step: Union[int, float], round_number: int = 2):
 
    temp = []
    while True:
        if start < end:
            temp.append(round(start, round_number))
            start += step
        else:
            break
    return temp


def surface3d_data():    
    for t1 in float_range(0, math.pi*2+math.pi/30, math.pi/30):
        for t0 in float_range(0, math.pi+math.pi/30, math.pi/30): 
            y = math.sin(t1)*math.sin(t0)
            x = math.cos(t1)*math.sin(t0)
            z = math.cos(t0)
            yield [x, y, z]

(
    Surface3D()
    .add(
        series_name="中秋快乐",
        shading="color",
        data=list(surface3d_data()),
        xaxis3d_opts=opts.Axis3DOpts(type_="value"),
        yaxis3d_opts=opts.Axis3DOpts(type_="value"),
        grid3d_opts=opts.Grid3DOpts(width=100, height=100, depth=100),
    )
    .set_global_opts(
        visualmap_opts=opts.VisualMapOpts(
            dimension=1,
            max_=1,
            min_=-1,
            range_color=[
                "#ffffbb",                
                "#ffff00",                
                "#bbbb00",
            ],
        )    
    )
    .render("moon.html")
)


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BlackPercy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值