2

I am trying to plot an ellipsoid so, I thought I would amend the example code for a sphere from the matplotlib 3D plotting page.

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Ellipsoid
u = np.linspace(-np.pi/2.0,np.pi/2.0,100)
v = np.linspace(-np.pi,np.pi,100)
x = 10 * np.outer(np.cos(u), np.cos(v))
y = 10 * np.outer(np.cos(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.sin(v))


# Sphere
#u = np.linspace(0, 2 * np.pi, 100)
#v = np.linspace(0, np.pi, 100)
#x = 10 * np.outer(np.cos(u), np.sin(v))
#y = 10 * np.outer(np.sin(u), np.sin(v))
#z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))

ax.plot_surface(x, y, z,  rstride=4, cstride=4, cmap = cm.copper)
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.set_zlabel('z-axis')
plt.show()

If you run the code you will see that the plot returns an aesthetically pleasing half inside out boat like surface but sadly not an ellipsoid.

Have included the sphere code (commented out) for comparison.

Is there something obvious here that I'm missing?

DrBwts
  • 3,470
  • 6
  • 38
  • 62

1 Answers1

2

Why did you change the parametrization? Starting with the sphere as an example, you only have to change the semi-axis lengths:

# Ellipsoid
u = np.linspace(0, 2.*np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 60 * np.outer(np.cos(u), np.sin(v))
y = 20 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
hitzg
  • 12,133
  • 52
  • 54
  • Yes of course! I have been completely over thinking the problem. Thank you I needed that external view – DrBwts Feb 09 '15 at 10:26
  • Glad that I could help. Feel free to accept this answer and/or upvote it. This will indicate to other users that your problem has been resolved. – hitzg Feb 09 '15 at 11:47
  • I dont have enough rep points to upvote it but have accepted the answer, thanks again. – DrBwts Feb 10 '15 at 15:26