python绘制三维散点图
时间: 2023-08-30 11:09:41 浏览: 37
可以使用Python的三维数据可视化库如 Matplotlib、Mayavi 来绘制三维散点图。
下面是使用Matplotlib绘制三维散点图的示例代码:
```
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
x = [1,2,3,4,5,6,7,8,9,10]
y = [2,3,4,5,1,6,2,1,7,2]
z = [1,2,6,3,2,7,3,3,2,1]
ax.scatter(x, y, z)
plt.show()
```
通过运行上述代码,就可以得到一个三维散点图。
相关问题
python绘制三维散点图代码
以下是用 Python 绘制三维散点图的代码:
```
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
# 生成随机数据
np.random.seed(2021)
n = 100
x = np.random.standard_normal(n)
y = np.random.standard_normal(n)
z = np.random.standard_normal(n)
# 创建 3D 坐标轴
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# 绘制散点图
ax.scatter(x, y, z, c='r', marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
```
请帮我写一段python绘制三维散点图的代码
当然可以,以下是一段绘制三维散点图的Python代码:
```python
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [5, 6, 2, 3, 13, 4, 1, 2, 4, 8]
z = [2, 3, 3, 3, 5, 7, 9, 11, 9, 10]
ax.scatter(x, y, z, c='r', marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
```
这段代码使用了Matplotlib库和mplot3d工具包,可以绘制出一个简单的三维散点图。