【发布时间】:2022-01-20 13:43:21
【问题描述】:
我有这种格式的数据:
from itertools import permutations
import random
values = [val for val in range(5)]
xy_coordinate_pairs = list(permutations(values, 2))
z_values = [random.randint(0,20) for val in range(len(xy_coordinate_pairs))]
data = dict(zip(xy_coordinate_pairs,z_values))
{(0, 1): 4,
(0, 2): 20,
(0, 3): 16,
(0, 4): 12,
(1, 0): 6,
(1, 2): 3,
(1, 3): 6,
(1, 4): 16,
(2, 0): 19,
(2, 1): 17,
(2, 3): 17,
(2, 4): 11,
(3, 0): 18,
(3, 1): 13,
(3, 2): 11,
(3, 4): 20,
(4, 0): 20,
(4, 1): 19,
(4, 2): 6,
(4, 3): 0}
我想将其绘制为 3d 曲面图,其中 x 和 y 坐标分别是键元组中的第一个和第二个值,z(曲面图的高度)是字典值。我该怎么做呢?
非常感谢,祝您有美好的一天。
【问题讨论】:
-
不要创建元组和字典。使用 numpy 数组和 np.meshgrid 直接绘制数据。请参阅 Surface plots in matplotlib 或 matplotlib documentation。
标签: python pandas matplotlib data-visualization