Why does my code to plot a cone actually generate a roof? per this post, this formula

$Z = 1 - \sqrt{X^{2} + Y^{2}}$

generates a cone where the point is at (0, 0, 1) and it spreads out below that. It meets the x-y plane at the unit circle



I am trying to reproduce with Python

ax = plt.figure().gca(projection='3d')
xx, yy = np.meshgrid(np.arange(-1,1.1,.1), np.arange(-1,1.1,.1))
zz = 1 - np.sqrt(xx**2, yy**2)
ax.plot_surface(xx, yy, zz, alpha=.5)


and get this "roof"



each of xx, yy, zz is a 21 by 21 matrix, even if I increase them to 210 by 210, nothing changes, what am I missing?
You need to change the call to sqrt from:

np.sqrt(xx**2, yy**2)


to:

np.sqrt(xx**2 + yy**2)


Otherwise you're passing an array of values to the function and will be returned an array of values for the answer.

See here for details:


  &gt;&gt;&gt; np.sqrt([1,4,9])
  
  array([ 1.,  2.,  3.])