Creating a 3D plot from a 3D numpy array

后端 未结 2 624
[愿得一人]
[愿得一人] 2020-12-24 13:10

Ok, so I feel like there should be an easy way to create a 3-dimensional scatter plot using matplotlib. I have a 3D numpy array (dset) with 0\'s where I don\'t

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 13:54

    If you wanted to avoid using the nonzero option (for example, if you had a 3D numpy array whose values were supposed to be the color values of the data points), you could do what you do, but save some lines of code by using ndenumerate.

    Your example might become:

    for index, x in np.ndenumerate(dset):
        if x == 1:
            ax.scatter(*index, c = 'red')
    

    I guess the point is just that you dont need to have nested for loops to iterate through multidimensional numpy arrays.

提交回复
热议问题