1

I have a 4D data like below. I really want to make a 4D plot with Matplotlib. The plot I am looking for is exactly like the 4D scatter plot made by @user3666197 It looks so great. I did some research but still have no idea how to make one like it. user3666197 briefly mentioned Adding { 3D | 4D | 5D } transcoding, but I have no clue how to do that.

Here is the picture.

A sample of my data below:

    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
Drise
  • 4,310
  • 5
  • 41
  • 66
Lenny
  • 29
  • 1
  • 9
  • 1
    [This SO anwer](https://stackoverflow.com/a/24169256/1620879) takes you most of the way there. – jorgeh Mar 09 '18 at 18:33
  • Looking at that answer you mention, this is indeed pretty useless. It essentailly only tells you that you have the option to encode your fourth dimension either in scatter dot size or color. I guess it is up to you to decide. Once you have decided that you should easily find examples on SO that (unlike the linked answer) actually show the code to achieve that. This question here seems too broad at the moment. – ImportanceOfBeingErnest Mar 09 '18 at 18:37
  • Linking you to e.g. [this question](https://stackoverflow.com/questions/45324258/draw-many-spheres-efficiently): From the question you see how to plot spheres with matplotlib, the answer tells how to plot them more efficiently with mayavi. – ImportanceOfBeingErnest Mar 09 '18 at 18:39

1 Answers1

-1

This is how you can quickly plot 4D random data. First three variables are on the axis, and the fourth being color:

 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()
  • This code first throws `NameError: name 'plt' is not defined`. After replacing `plot.figure()` with `mplt.figure()`, it throws `ValueError: Unknown projection '4d'`. Python 3.7.5, Matplotlib 3.0.2. – miguelmorin Dec 19 '19 at 09:27