import numpy as np
import pandas as pd
import plotly.express as px


def get_data(size):
    R = np.linspace(0, 2 * np.pi, size)

    x = np.linspace(start=0, stop=size, num=size, dtype=np.int)
    y = np.linspace(start=0, stop=size, num=size, dtype=np.int)
    z = -np.cos(R)

    res = []
    for i in range(size):
        bundle = {'x': x[i], 'y': y[i], 'z': z[i]}
        res.append(bundle)

    df = pd.DataFrame(data=res, columns=['x', 'y', 'z'])
    return df


if __name__ == '__main__':
    SIZE = 100
    df = get_data(SIZE)

    fig = px.scatter_3d(data_frame=df,
                        x=df['x'],
                        y=df['y'],
                        z=df['z'],
                        width=1200,
                        height=800,
                        color='z',
                        )
    fig.show()

 

输出结果:

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐