数据可视化
程序员文章站
2024-02-12 18:12:28
...
可视化数据
画3D散点图
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 空白图象
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Define the number of values
n = 250
# lambda函数生成给定范围的值
f = lambda minval, maxval, n: minval + (maxval - minval) * np.random.rand(n)
# 生成值
x_vals = f(15, 41, n)
y_vals = f(-10, 70, n)
z_vals = f(-52, -37, n)
# 画出这些值
ax.scatter(x_vals, y_vals, z_vals, c='k', marker='o')
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zl