Why Z has to be 2-dimensional for 3d plotting in matplotlib
问题 I am trying to plot 3d Surface plots using code from this site using matplotlib: X,Y and Z are obtained as below: from math import pi from numpy import cos, meshgrid alpha = 0.7 phi_ext = 2 * pi * 0.5 def flux_qubit_potential(phi_m, phi_p): return 2 + alpha - 2 * cos(phi_p)*cos(phi_m) - alpha * cos(phi_ext - 2*phi_p) phi_m = linspace(0, 2*pi, 100) phi_p = linspace(0, 2*pi, 100) X,Y = meshgrid(phi_p, phi_m) Z = flux_qubit_potential(X, Y).T And 3d plotting is done with following code: from mpl