RazerM / orbital

High level orbital mechanics package.
MIT License
91 stars 35 forks source link

Problem with 3D plots #16

Open calumpark opened 4 years ago

calumpark commented 4 years ago

When trying to plot a 3D graph I am getting the error message 'NameError: name 'plot3d' is not defined' when using code 'plot3d(molniya)' as it is provided in the examples. I'm using Python 2.7. Is there extra code I'm missing the plot this graph or is it a problem within Orbital?

I've also tried using 'from mpl_toolkits import mplot3d' then ax = plt.axes(projection='3d') ax.plot3D(molniya)' but this returns an error 'TypeError: plot() takes at least 3 arguments (2 given)'

Any help would be appreciated.

garbagetrash commented 3 years ago

I've included minimal working code for my setup using python 3.8.10, numpy 1.21, and matplotlib 3.4.2 below. That being said, I had to edit the plotting.py file a bit to make it work (PR incoming), and the animate feature still isn't working for me. The fixes in plotting.py are just wrapping the number of points parameters in the numpy.linspace() calls with an int() typecast since that's what numpy expects (vs floats.)

$ cat plot3d.py 
from numpy import radians
from scipy.constants import kilo

from orbital import earth, KeplerianElements, Maneuver, plot, plot3d

from orbital import earth_sidereal_day

import matplotlib.pyplot as plt

molniya = KeplerianElements.with_period(
    earth_sidereal_day / 2, e=0.741, i=radians(63.4), arg_pe=radians(270),
    body=earth)

# Simple circular orbit
orbit = KeplerianElements.with_altitude(1000 * kilo, body=earth)

plot3d(molniya)
plt.show()
RazerM commented 3 years ago

I've merged #22