Incorrect colouring of Surface plot

60 views Asked by At

I'm currently trying to create a surface plot of a laser energy output using the following code:

Xx_array = np.array(Xx)
X_data_array = np.array(Zx)

fig = plt.figure(figsize = (14, 6))

ax4 = fig.add_subplot(111, projection = '3d');
surfX = ax4.plot_surface(Xx_array.T, X_fixed_Y_axis, X_data_array.T,
                         rstride = 1, cstride = 1, antialiased = False,
                         cmap=cm.coolwarm, linewidth = 0);

fig.colorbar(surfX, shrink=0.5, aspect=4);

The only problem is that it does not seem to colour code the plot properly and makes the whole thing red. This is obviously incorrect because I have another plot which contains extremely similar data but colours correctly. I've been through the code carefully to look for discrepancies but none can be found. Is there something I'm missing? The colour coding bar is also not scaled correctly and doesn't follow the expected values nor the actually colour coding of the plot.

Code for the other data that works correctly is as follows:

Xy_array = np.array(Xy)
Y_data_array = np.array(Zy)

fig = plt.figure(figsize = (14, 6))

ax5 = fig.add_subplot(111, projection = '3d')
surfY = ax5.plot_surface(Xy_array.T, Y_fixed_Y_axis, Y_data_array.T, 
                         rstride = 1, cstride = 1, antialiased = False, 
                         cmap=cm.coolwarm, linewidth = 0);

fig.colorbar(surfY, shrink = 0.5, aspect = 4);

I've tried manually setting the data to scale by but this sends the whole plot blue:

m = cm.ScalarMappable(cmap=cm.coolwarm)
m.set_array(X_data_array.T)

Any advice would be great. Thanks.

0

There are 0 answers