0

I ran a series of simulations and want to create a response surface of the performance based off my two parameters, tol and eta. The issue I'm having is actually plotting this in python. I have the vectors vec_tol (of dimension nx1) and vec_eta (mx1), and two matrices of the performance t_osa_adj (dimension nxm) and sdn_osa_sol (also nxm). I would like to plot a surface plot of [x,y,z] = [vec_tol,vec_eta,t_osa_adj] colored by sdn_osa_sol and I keep running into this error in python:

"ValueError: shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 0 with shape (16,) and arg 1 with shape (10,)."

My understanding is that this is because for the plot_surface command to work n must be equal to m. How do I fix this? I have put a snippet of the code below.

fig = plt.figure(figsize = (8, 7), facecolor='white')
ax = fig.add_subplot(projection='3d')
surf = ax.plot_surface(vec_tol, vec_eta, t_osa_adj, facecolors = cm.jet(np.log(sdn_osa_sol)), linewidth=0, antialiased=False)

Thank you.

EMP
  • 193
  • 1
  • 10
  • No, the data doesn't need to be square. But it needs to be formed as 2D arrays. `X` needs to be a 2D array of x coordinates, `Y` the corresponding y coordinates and `Z` the corresponding z coordinates. Typically, `X, Y = np.meshgrid(vec_tol, vec_eta)` is used to combine the 1D arrays into 2D arrays. See also e.g. [surface plots in matplotlib](https://stackoverflow.com/questions/9170838/surface-plots-in-matplotlib) – JohanC May 14 '22 at 14:52
  • I made the change you suggested and then got: ValueError: shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 0 with shape (10, 16) and arg 2 with shape (16, 10). Do you know why that is? – EMP May 14 '22 at 15:55
  • The dimensions seem to be interchanged. Try `X, Y = np.meshgrid(vec_ets, vec_tol)` or instead use `t_osa_adj.T` for Z. By the way `jet` has a bad reputation as it creates highlights at strange spots. You might want to use `cmap='turbo'` instead – JohanC May 14 '22 at 18:21

0 Answers0