python三维交互可视化工具plotly使用

本文介绍了如何使用Python的plotly库生成3D散点图,展示了如何处理随机数据并添加中心点标记,以及如何设置坐标轴标题和布局。
摘要由CSDN通过智能技术生成

三维数据可视化工具使用

import plotly.graph_objects as go
import numpy as np

# 生成随机点
data = np.random.uniform(-3,3,(100000, 2))
Z = np.exp(-((data[:, 0] - 0)**2 / (2*1**2) + (data[:, 1] - 0)**2 / (2*1**2)))

scatter1 = go.Scatter3d(x=data[:, 0], y=data[:, 1], z=Z, mode='markers', marker=dict(color='blue',size=1,opacity=0.8), name='data')
scatter2 = go.Scatter3d(x=[0], y=[0], z=[0], mode='markers', marker=dict(color='red',size=6,opacity=0.8), name='centroids')
fig = go.Figure(data=[scatter1, scatter2])

fig.update_layout(
    width=1000,
    height=800,
    margin=dict(l=50, r=50, b=50, t=50)
)

fig.update_layout(
    title='X-Y-Heading',
    scene=dict(
        xaxis_title='X',
        yaxis_title='Y',
        zaxis_title='Heading'
    ),   
)
# fig.write_html('path.html')  # 以网页形式保存
fig.show()

在这里插入图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python中,您可以使用许多库来进行三维数据可视化,其中包括: 1. Matplotlib:Matplotlib是Python中最流行的可视化库之一,它提供了许多用于三维数据可视化的函数和工具。您可以使用Matplotlib中的mplot3d工具箱来创建三维图形。 以下是一个使用Matplotlib创建三维散点图的示例代码: ``` python import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np # 创建数据 x = np.random.normal(0, 1, 100) y = np.random.normal(0, 1, 100) z = np.random.normal(0, 1, 100) # 创建3D图形 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # 绘制散点图 ax.scatter(x, y, z) # 设置坐标轴标签 ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label') # 显示图形 plt.show() ``` 2. PlotlyPlotly是一个基于Web的交互式可视化库,它支持许多类型的三维图形。您可以使用Plotly创建各种三维图形,例如散点图、表面图、等高线图等。 以下是一个使用Plotly创建三维散点图的示例代码: ``` python import plotly.graph_objs as go import numpy as np # 创建数据 x = np.random.normal(0, 1, 100) y = np.random.normal(0, 1, 100) z = np.random.normal(0, 1, 100) # 创建散点图 fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z, mode='markers')]) # 设置坐标轴标签 fig.update_layout(scene=dict(xaxis_title='X Label', yaxis_title='Y Label', zaxis_title='Z Label')) # 显示图形 fig.show() ``` 无论您选择使用哪个库,都可以创建出漂亮的三维数据可视化图形。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值