Python数据可视化:plotly.express三维坐标数据点(3D坐标)
import numpy as npimport pandas as pdimport plotly.express as pxdef 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
·
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()
输出结果:
更多推荐
已为社区贡献7条内容
所有评论(0)