![]() |
scatter3D different markers per data - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: scatter3D different markers per data (/thread-37316.html) |
scatter3D different markers per data - erdemath - May-26-2022 I have an issue with data visualization in 3D scatter plot. I have regionally stratified some data, say data_A, data_B, data_C. I need to display them in 3D scatter plot with different markers, or colours, per data. I have been trying with many things, but I cannot get what I need. Here is one of the examples I have coded up; 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 = data_all[0] DG_sd = data_all[1] CA3_sd = data_all[2] ax.scatter3D(EC_sd, DG_sd, CA3_sd, marker=marker_list[data_count]) fig.tight_layout() plt.show()Result is attached. There is something annoying here. RE: scatter3D different markers per data - deanhystad - May-26-2022 If you look at EC_sd, what is it? My guess is it is a numpy array and that your loop only runs once. I can't tell because I don't know what data_A, data_B or data_C are. What were you planning to do with region? RE: scatter3D different markers per data - erdemath - May-27-2022 data_A, data_B, data_C are numpy arrays belonging to the regions A,B and C. RE: scatter3D different markers per data - erdemath - May-27-2022 Sorry! I made a typo in the code. Here's the corrected lines, it must be clearer now what I do with the variable 'region'; 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() RE: scatter3D different markers per data - deanhystad - May-27-2022 (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 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? RE: scatter3D different markers per data - erdemath - May-27-2022 (May-27-2022, 03:38 PM)deanhystad Wrote:Each is of 1D.(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? |