May-27-2022, 03:38 PM
(This post was last modified: May-27-2022, 05:39 PM by deanhystad.)
(May-27-2022, 09:03 AM)erdemath Wrote: data_A, data_B, data_C are numpy arrays belonging to the regions A,B and C.What are the dimensions of data_A, data_B, data_C? 1D, 2D, 3D?
I tried this with 1D arrays. If data_A is a 3D array you can ignore all that follows.
import numpy as np import matplotlib.pyplot as plt data_A = np.linspace(0.0, 1.0, 11) data_B = np.linspace(1.0, 2.0, 11) data_C = np.linspace(2.0, 3.0, 11) data_all = np.vstack((data_A, data_B, data_C)) fig, ax = plt.subplots(figsize=(12, 6)) ax = plt.axes(projection="3d") case_count = 0 marker_list = ["o", "x", "s"] ax = fig.add_subplot(1, 1, 1, projection="3d") for data_count, region in enumerate(zip(data_all)): EC_sd = region[0] DG_sd = region[1] CA3_sd = region[2] ax.scatter3D(EC_sd, DG_sd, CA3_sd, marker=marker_list[data_count]) fig.tight_layout() plt.show()When I print data_all I see that it is a 2D array with shape 3, 11
Output:[[0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. ]
[1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2. ]
[2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3. ]]
Your zip command is not going to do what you think. I suspect you want the first iteration to use dataA[0], data_B[0], data_C[0], the second iteration to use data_A[1], data_B[1], data_C[1] and so on. But instead of region containing (data_A[0], data_B[0], data_C[0]) it contains (data_A,). The next time through the loop it will contain (data_B,) and the third time (data_C,). When I run the program I get an index error because there is only one element in region, data_A. region[1] is index out of range.If you want to zip to return (data_A[N], data_B[N], data_C[N]) you could do this:
for data_count, region in enumerate(zip(*data_all)): EC_sd = region[0] DG_sd = region[1] CA3_sd = region[2]It would be even easier to not make data_all and use the source arrays directly.
for data_count, region in enumerate(zip(data_A, data_B, data_C)): marker = marker_list[data_count % len(marker_list)] ax.scatter3D(*region, marker=marker_list[data_count])Now I get a different IndexError. The problem is all my data arrays are length 11, so the loop runs 11 times. Fourth time through the loop data_count == 3, and there is no marker_list[3].
What are the markers supposed to indicate? You are making a 3D scatter plot, so I would think that data_A, data_B, data_C are the X, Y and Z coordinates. In others (data_A[0], data_B[0], data_C[0]) is one point. Why would I used different markers to print my 11 points?