I have 4 variables that i would like to plot, i have a dictionary containing all the data i need which give x,y,z and c data. I would like to plot the position of each data point using the position of x,y and z with the fourth variable coloured using the range of 0 to 1. I can create the plot with each dataset from the key of the dictionary added onto the plot but dont know how to add a colour bar to this.
this is the section of my code that is user for plotting:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X (m)')
ax.set_ylabel('Y (m)')
ax.set_zlabel('Z (m)')
ax.set_xlim(0,0.1)
ax.set_ylim(0,0.04)
ax.set_zlim(-0.02,0.04)
cmp = plt.cm.get_cmap('RdYlBu')
for i in range(1,len(coordinates)):
x = coordinates[i,0]
y = coordinates[i,1]
X = plot_data["x-" + str(x) + "-y" + str(y)][:,0]
Y = plot_data["x-" + str(x) + "-y" + str(y)][:,1]
Z = plot_data["x-" + str(x) + "-y" + str(y)][:,2]
c = plot_data["x-" + str(x) + "-y" + str(y)][:,3]
ax.scatter(X,Y,Z,c=c,vmin=0,vmax=1,cmap=cmp)
fig.colorbar(ax)
plt.show()
The code loops through my dictionary fine and produces a plot i am happy with when i remove:
fig.colorbar(ax)
when i include it, the plot falls apart, is there a way to implement a colour bar for all this data that is being plot seperately?