Python Forum
scatter3D different markers per data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scatter3D different markers per data
#1
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.

Attached Files

Thumbnail(s)
   
Reply
#2
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?
Reply
#3
data_A, data_B, data_C are numpy arrays belonging to the regions A,B and C.
Reply
#4
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()
Reply
#5
(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?
Reply
#6
(May-27-2022, 03:38 PM)deanhystad Wrote:
(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?
Each is of 1D.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Matplotlib 2 lines with different markers medatib531 0 1,715 Sep-15-2020, 09:47 PM
Last Post: medatib531

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020