import astropy.units as u
import numpy as np
__all__ = ['draw_ellipse']
[docs]
def draw_ellipse(equatorial_radius, oblateness=0.0, center_f=0.0, center_g=0.0,
position_angle=0.0, center_dot=False, ax=None, **kwargs):
"""Plot an ellipse with the given input parameters.
Parameters
----------
equatorial_radius : `float`, `int`, array-like
Semi-major axis of the ellipse, in km.
oblateness : `float`, `int`, array-like, optional
Oblateness of the ellipse.
center_f : `float`, `int`, array-like, optional
Coordinate of the ellipse center in the f direction, in km.
center_g : `float`, `int`, array-like, optional
Coordinate of the ellipse center in the g direction, in km.
position_angle : `float`, `int`, array-like, optional
Pole position angle of the ellipse, in degrees. Zero is in the North
direction ('g-positive'). Positive clockwise.
center_dot : `bool`, optional
If True, plots a dot at the center of the ellipse.
ax : `matplotlib.pyplot.Axes`, optional
Axes where the ellipse is plotted. If `None`, the current axes are
used.
**kwargs
Additional keyword arguments passed directly to matplotlib.
"""
import matplotlib.pyplot as plt
equatorial_radius = np.array(equatorial_radius, ndmin=1)
oblateness = np.array(oblateness, ndmin=1)
center_f = np.array(center_f, ndmin=1)
center_g = np.array(center_g, ndmin=1)
position_angle = np.array(position_angle, ndmin=1)
theta = np.linspace(-np.pi, np.pi, 1800)
ax = ax or plt.gca()
if len(equatorial_radius) == 1:
if 'color' not in kwargs:
kwargs['color'] = 'black'
if 'lw' not in kwargs:
kwargs['lw'] = 2
else:
if 'color' not in kwargs:
kwargs['color'] = 'gray'
if 'lw' not in kwargs:
kwargs['lw'] = 0.1
if 'alpha' not in kwargs:
kwargs['alpha'] = 0.1
if 'zorder' not in kwargs:
kwargs['zorder'] = 0.5
for i in np.arange(len(equatorial_radius)):
circle_x = equatorial_radius[i] * np.cos(theta)
circle_y = equatorial_radius[i] * (1.0 - oblateness[i]) * np.sin(theta)
pos_ang = position_angle[i] * u.deg
ax.plot(+circle_x * np.cos(pos_ang) + circle_y * np.sin(pos_ang) + center_f[i],
-circle_x * np.sin(pos_ang) + circle_y * np.cos(pos_ang) + center_g[i],
**kwargs)
if center_dot:
kwargs.pop('lw')
plt.plot(center_f, center_g, '.', **kwargs)
plt.axis('equal')