orbital icon indicating copy to clipboard operation
orbital copied to clipboard

How to get the animation plots working in Mac OS X

Open OrbitalMechanic opened this issue 8 years ago • 14 comments

I'm attempting to get one of the examples running on a Mac Book Pro running Mac OS X 10.11.4 (El Capitan). What do I need to do to get the plot and plot3d animated plots to function? Please advise.

molniya_ex.py.txt

OrbitalMechanic avatar Apr 21 '16 02:04 OrbitalMechanic

I can confirm the issue for me, but I'm not sure what the problem is.

RazerM avatar Apr 23 '16 23:04 RazerM

Let me see if I can state the problem in another way. I'm trying to reproduce the two animation examples posted at http://pythonhosted.org/OrbitalPy/examples/plotting/plotting/#animation. The file I've attached to this note successfully reproduces all the plots correctly with the exception of the two animation plots. No animated plots are output.

Any advice.

Sam Dupree.

On 4/23/16 19:35:17, Frazer McLean wrote:

I can confirm the issue for me, but I'm not sure what the problem is.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/RazerM/orbital/issues/2#issuecomment-213852984

#!/usr/bin/env python

-- coding: utf-8 --

from numpy import radians from scipy.constants import kilo

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

import matplotlib.pyplot as plt

plt.switch_backend('QT4Agg')

Create molniya orbit from period and eccentricity

from orbital import earth_sidereal_day 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)

Simple plots

plot(molniya)

plot3d(molniya)

Animation

plot(molniya, title='Molniya 1', animate=True)

plot3d(molniya, title='Molniya 2', animate=True)

Maneuvers

man = Maneuver.hohmann_transfer_to_altitude(10000 * kilo)

plot(orbit, title='Maneuver 1', maneuver=man)

plot3d(orbit, title='Maneuver 2', maneuver=man)

import matplotlib.pyplot as plt plt.show()

OrbitalMechanic avatar Apr 24 '16 00:04 OrbitalMechanic

When I said problem, I meant the bug itself; I understood what you meant.

RazerM avatar Apr 24 '16 01:04 RazerM

Any thoughts on the solution to this bug?

OrbitalMechanic avatar Jun 25 '16 22:06 OrbitalMechanic

The animation works on Matplotlib 1.4.3. I'll need to investigate what changed between 1.4 and 1.5

RazerM avatar Jun 25 '16 22:06 RazerM

I traced the problem with git bisect to this commit: matplotlib/matplotlib@03d97f239c2cff6467b9e80e951ea429d96c3be6

So they fixed GC on Python 3 (are you using Python 3?) and we're not storing a reference to the FuncAnimation instance, so it gets cleaned up.

I'll release a new version to PyPI once I double check my fix against released version of Matplotlib.

RazerM avatar Jun 25 '16 23:06 RazerM

I'm using Python 2.7.x. Will that make a difference?

Sam Dupree.

On 6/25/16 19:41:38, Frazer McLean wrote:

I traced the problem with git bisect to this commit: matplotlib/matplotlib@03d97f2 https://github.com/matplotlib/matplotlib/commit/03d97f239c2cff6467b9e80e951ea429d96c3be6

So they fixed GC on Python 3 (are you using Python 3?) and we're not storing a reference to the |FuncAnimation| instance, so it gets cleaned up.

I'll release a new version to PyPI once I double check my fix against released version of Matplotlib.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RazerM/orbital/issues/2#issuecomment-228576069, or mute the thread https://github.com/notifications/unsubscribe/AEjt9xdSZPw0viLMNb8tgP2vAkjDgNEkks5qPbyygaJpZM4IMS93.

OrbitalMechanic avatar Jun 25 '16 23:06 OrbitalMechanic

I'll check there too. Might mean it was always broken on Python 2.7.

RazerM avatar Jun 25 '16 23:06 RazerM

For now, you can get it to work by keeping a reference to the result of plot():

_ = plot(molniya, title='Molniya 1', animate=True)

RazerM avatar Jun 26 '16 02:06 RazerM

I'm still a novice when it comes to Python, so would you explain syntax of the _ = and what the statement _ = plot(molniya, title='Molniya 1', animate=True) does?

Thanks.

OrbitalMechanic avatar Jun 30 '16 02:06 OrbitalMechanic

@OrbitalMechanic the above merely means that you've instantiated the variable _ which assigns and holds the value of plot(molniya, title='Molniya 1', animate=True). From my understanding here there was some sort of latent cleanup which is where the issue is arising from. If I were you I would attempt to upgrade to Python 3.X and try. If @RazerM is able to resolve the issue in Python 3.X then I would go with that.

I also came across this library just today so I will try my best to reproduce and write back here in due course regarding any issues I encounter.

lewismc avatar Oct 11 '16 03:10 lewismc

Any results on solving this issue? I cannot generate any of the plots to generate in mac with python 2.7

I am able to generate the plots by including the following:

import matplotlib.pyplot as plt

and right after the plot command the plt.show() command:

plot(molniya, title='Molniya 1', animate=True) plt.show()

However, the plots are static, but I cannot get the animation to work.

f0n avatar Mar 24 '17 18:03 f0n

I've been away from orbital for some time now and am coming back to it. Presently, I'm running Python ver. 3.6.5 under the Anaconda distribution on a Mac Pro (desktop, Late 2012) running Mac OS X ver. 10.12.6 (Sierra).

The issue I'm having with getting animation working is that I can get an animated plot, but I cannot save the animation as a *.mp4 file. The desired output file is allocated, but nothing is output to it.

The output I get from Python is as follows.

**/Users/user/.bash_profile: line 479: /Applications/mesasdk/bin/mesasdk_init.sh: No such file or directory /Users/user/.bash_profile: line 485: /Applications/madsdk/bin/madsdk_init.sh: No such file or directory Traceback (most recent call last): File "/Users/user/orbital/Keplerain Orbit Trajectory Plots - OrbitalPy(python2)/OrbitalPy_StateVector.py", line 66, in line__anim.save('MyOrbit-1.mp4') File "/Users/user/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1174, in save writer.grab_frame(savefig_kwargs) File "/Users/user/anaconda3/lib/python3.6/contextlib.py", line 99, in exit self.gen.throw(type, value, traceback) File "/Users/user/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 232, in saving self.finish() File "/Users/user/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 358, in finish self.cleanup() File "/Users/user/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 395, in cleanup out, err = self._proc.communicate() File "/Users/user/anaconda3/lib/python3.6/subprocess.py", line 843, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "/Users/user/anaconda3/lib/python3.6/subprocess.py", line 1505, in _communicate selector.register(self.stdout, selectors.EVENT_READ) File "/Users/user/anaconda3/lib/python3.6/selectors.py", line 351, in register key = super().register(fileobj, events, data) File "/Users/user/anaconda3/lib/python3.6/selectors.py", line 237, in register key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data) File "/Users/user/anaconda3/lib/python3.6/selectors.py", line 224, in _fileobj_lookup return _fileobj_to_fd(fileobj) File "/Users/user/anaconda3/lib/python3.6/selectors.py", line 39, in _fileobj_to_fd "{!r}".format(fileobj)) from None ValueError: Invalid file object: <_io.BufferedReader name=18>

The Python program I'm running is contained in the attached file.

OrbitalPy_StateVector.py.txt

Any thoughts?

OrbitalMechanic avatar Oct 18 '18 04:10 OrbitalMechanic

I believe I found a workaround form the discussion posted at https://stackoverflow.com/questions/23856990/cant-save-matplotlib-animation. I added the path for ffmpeg on my system to my code as seen in the file attached to this posting and it now saves the .mp4 file.

Hope this helps.

OrbitalPy_StateVector-1.py.txt

OrbitalMechanic avatar Oct 21 '18 04:10 OrbitalMechanic