将数值matplotlib轴映射到曲面p中的“string”变量中

2024-05-19 00:45:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题是:我有一个表,我想从中获得三维曲面图,如下面代码中所示,但x和y单位上的记号需要一些“重新映射”,即[0,1,…]必须变成[“apple”,“orange”等]。在

这对我的可视化非常重要(我不能切换到分类图表,因为我会失去“表面”功能)。在

在下面的代码中,tablepandas Dataframe,它是2D数组的“类似SQL”的表示形式加上输出值(如几乎所有matplolib案例研究所示)。在

####################################################
         position  time_digitized  value
    0           0               0  0.636
    1           0               3  0.323
    2           0               1  0.783
    3           0               2  0.494
    4           0               4  0.452
    5           0               7  0.212
    6           0               5  0.465
    7           0               6  0.334
    8           0               8  0.182
    9           0              11  0.256
    10          0               9  0.244
####################################################

 from mpl_toolkits.mplot3d.axes3d import Axes3D
 import matplotlib.pyplot as plt
 from matplotlib import cm

 fig = plt.figure()
 ax = Axes3D(fig)
 surf = ax.plot_trisurf(
      table.loc[:, 'position'],
      table.loc[:, 'time_digitized'],
      table.loc[:, 'value'],
      cmap=cm.ocean,
      linewidth=0.1)
 fig.colorbar(surf, shrink=0.5, aspect=5)
 plt.show()

Tags: 代码fromimporttimematplotlibvaluetablefig

热门问题