1

I would like to plot the line: (x^2)/11.39 + (y^2)/6.25 = 1 rotated around the x-axis for a project I am working on.

I have used matplotlib to graph some 3D planes before but am unable to figure out how I would draw the revolution of a line around the x-axis.

I'm thinking I would have to use ax.plot_surface but am not quite sure how.

Thanks.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
ArduinoBen
  • 161
  • 1
  • 8
  • Related questions: [Ploting solid of revolution in Python 3 (matplotlib maybe)](https://stackoverflow.com/questions/36464982/ploting-solid-of-revolution-in-python-3-matplotlib-maybe); [Creating a Surface of Revolution](https://stackoverflow.com/questions/51801498/creating-a-surface-of-revolution) (a surface obtained by rotating a curve around one of the axes is usually called a "surface of revolution", so I googled "matplotlib surface of revolution" and found these two questions) – Stef Dec 15 '21 at 07:42
  • Soooo did you manage to plot what you wanted? – Stef Dec 21 '21 at 12:19
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 21 '21 at 17:42
  • sorry yeah I marked your answer as correct. – ArduinoBen Jan 25 '22 at 00:49

1 Answers1

1

Here are my meager attempts using plot_surface, meshgrid, and trigonometry:

import numpy as np
import matplotlib.pyplot as plt

a2, b2 = 11.39, 6.26

X = np.linspace(-np.sqrt(a2), np.sqrt(a2), 100)
Theta = np.linspace(0, 2.1*np.pi, 1000)
X, Theta = np.meshgrid(X, Theta)

Y0 = np.sqrt(b2 * (1 - X**2 / a2))
Y = Y0 * np.cos(Theta)
Z = Y0 * np.sin(Theta)

fig,ax = plt.subplots(subplot_kw={'projection':'3d'})
ax.set_box_aspect((np.ptp(X), np.ptp(Y), np.ptp(Z)))
ax.plot_surface(X, Y, Z)
ax.set_xlabel('x')
plt.show()

Ellipsoid revolving ellipse around x-axis matplotlib

Stef
  • 13,242
  • 2
  • 17
  • 28