马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 george1108 于 2021-7-9 15:59 编辑
求诸位大佬:
例如:
[[0 1 2 3 4 5 6 7]
[1 0 3 2 5 4 7 6]
[2 3 0 1 6 7 4 5]
[3 2 1 0 7 6 5 4]
[4 5 6 7 0 1 2 3]
[5 4 7 6 1 0 3 2]
[6 7 4 5 2 3 0 1]
[7 6 5 4 3 2 1 0]]
上面的矩阵,想做成离散点的3D图。
x--列坐标,y--行坐标, z--对应矩阵值
(x, y, z)
(0, 0, 0)
(2, 7, 5)
(7, 5, 2)
x,y 我可以用linspace(),z的值该如何写?
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- fig = plt.figure()
- ax = fig.gca(projection='3d')
- count = 100
- range_ = 100
- data = [[0, 1, 2, 3, 4, 5, 6, 7],
- [1, 0, 3, 2, 5, 4, 7, 6],
- [2, 3, 0, 1, 6, 7, 4, 5],
- [3, 2, 1, 0, 7, 6, 5, 4],
- [4, 5, 6, 7, 0, 1, 2, 3],
- [5, 4, 7, 6, 1, 0, 3, 2],
- [6, 7, 4, 5, 2, 3, 0, 1],
- [7, 6, 5, 4, 3, 2, 1, 0]]
- x, y, z = [], [], []
- for row in range(len(data)):
- for column in range(len(data[row])):
- x.append(row)
- y.append(column)
- z.append(data[row][column])
- ax.scatter(x, y, z, s=z, c=z)
- ax.set_xlabel('Row')
- ax.set_ylabel('Col')
- ax.set_zlabel('Value')
- plt.show()
复制代码
|