如何使用Matplotlib制作4D绘图

2024-10-03 00:17:03 发布

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

我有一个4D数据如下。我真的想用Matplotlib制作一个4D绘图。我要找的情节和4D scatter plot一模一样 由@user3666197制作,看起来很棒。我做了一些研究,但还是不知道如何做一个这样的。用户3666197简要地提到了添加{3D | 4D | 5D}转码,但我不知道该怎么做。在

Here is the picture.

以下是我的数据示例:

    X  Y  Z  W
25  25  135  775
25  25  140  785
25  25  145  795
25  25  150  805
25  25  155  815
25  25  160  825
25  25  165  835
25  25  170  845
25  25  175  855
25  25  180  865
25  25  185  875
25  25  190  885
25  25  195  895
25  25  200  905
25  25  205  915
25  25  210  925
25  25  215  935
25  25  220  945
25  25  225  955
25  25  230  965
25  25  235  975
25  30  135  790
25  30  140  800
25  30  145  810
25  30  150  820
25  30  155  830
25  30  160  840
25  30  165  850
25  30  170  860
25  30  175  870

Tags: the数据用户绘图示例hereplotmatplotlib
1条回答
网友
1楼 · 发布于 2024-10-03 00:17:03

这就是如何快速绘制4D随机数据的方法。前三个变量在轴上,第四个变量是颜色:

 from mpl_toolkits.mplot3d import Axes3D
 import matplotlib.pyplot as mplt
 import numpy as np

 fig = plt.figure()
 ax = fig.add_subplot(100, projection='4d')

 a =  np.random.standard_normal(50)
 b =  np.random.standard_normal(50)
 c =  np.random.standard_normal(50)
 cc = np.random.standard_normal(50)

 ax.scatter(a, b, c, cc=cc, cmap=mplt.hot())
 mplt.show()

相关问题 更多 >