jupyter notebook 制作三元一次散点图和线图
时间: 2024-05-26 18:09:42 浏览: 183
Jupyter Notebook是一个交互式笔记本,可以用于数据清理和转换、数值模拟、统计建模、数据可视化、机器学习等多种应用。以下是在Jupyter Notebook中制作三元一次散点图和线图的步骤:
1. 导入必要的库:matplotlib和numpy
```
import matplotlib.pyplot as plt
import numpy as np
```
2. 生成数据:假设有三个变量x、y和z,每个变量有n个数据点,可以通过numpy库中的random函数生成随机数据:
```
n = 100
x = np.random.rand(n)
y = np.random.rand(n)
z = np.random.rand(n)
```
3. 绘制散点图:使用matplotlib库中的scatter函数,将x、y、z三个变量分别作为参数传入即可。
```
fig = plt.figure()
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()
```
4. 绘制线图:使用matplotlib库中的plot函数,将x、y、z三个变量分别作为参数传入即可。
```
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
```
阅读全文
相关推荐


















