Checking missing combination of co-ordinates in a 4D plot and adding dummy values for the missing combination

Viewed 70

I have a 4D plot plotted using matplotlib with the 4th dimension being color.

Lets assume the range of all the 3 axes to be 0 to 5. Array for plot looks something like this - [0,1,2,50],[1,2,3,40],[5,5,5,80]. So I will see 3 points on co-ordinates [0,1,2],[1,2,3],[5,5,5] in the graph when plotted (assuming a scatter plot).

My question is - is there any way to check the combinations of co-ordinates on the plot which do not have any points. In the above case, for example, there are no points on co-ordinates [1,2,4],[1,2,5],[0,0,0],[1,1,1],[4,1,2],[5,3,1] and so on. I can individually check if there is an element (between 0 and 5) which is not covered in a particular axis (using 'is in'). But how to get the missing combination of co-ordinates and then plot it in the graph with some dummy value ? Any leads or solution would be appreciated.

#create an empty list
list1 = []

#append elements to the list
list1.append([0,1,2,50])
list1.append([1,2,3,40])
list1.append([5,5,5,80])

using the scatter plot

cmap = LinearSegmentedColormap.from_list('mycmap', ['green', 'yellow', 'red']) 


fig = plt.figure()
ax = fig.gca(projection = '3d')
ax.set_xlim(0,5)
ax.set_ylim(0,5)
ax.set_zlim(0,5)

#convert list into array for slicing 
array1 = np.array(list1)
ax.scatter(array1[:,0],array1[:,1],array1[:,2],c=array1[:,3], cmap = cmap)
plt.show()

for the above i need to add zeroes to remaining co-ordinates. When i plot, the co-ordinates (0,1,2) gets a color corresponding to 50, (1,2,3) gets a color corresponding to 40 and similarly for co-ordinates (5,5,5). So the remaining co-ordinates should be appended with zeroes. Like (1,4,1,0), (1,3,5,0), (2,4,1,0) and so on.

1 Answers

This is how I would tackle this problem. Instead of checking on where there are not coordinates available, I'd initialize a matrix with the dummy value and set all available to the value they are supposed to have. It looks like this:

myData = [[0,1,2,50], [1,2,3,40], [5,5,5,80]]
fullMatrix = np.empty(shape=(6,6,6), dtype=np.int8) # 0 to 5 in each dimension
fullMatrix.fill(-1) # -1 is an example for the dummy value

for i in myData:
        fullMatrix[i[0],i[1],i[2]] = i[3]
Related