The plot module#
Common utils#
- pykep.plot.make_3Daxis(**kwargs)#
Constructs and returns a 3D axis. All kwargs are forwarded to the call to figure() in matplotlib.
- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: the 3D axis
Plotting planets#
- pykep.plot.add_sun(ax, **kwargs)#
Adds the Sun to ax. All kwargs are forwarded to the scatter method of ax.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): the 3D axis.- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: the 3D axis.
- pykep.plot.add_planet(ax, pla: planet, when, units=149597870700.0, **kwargs)#
Adds a planet to ax. All kwargs are forwarded to the scatter method of ax.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): the 3D axis.pla (
planet
): the planet.when (
epoch
orfloat
): the epoch (in mjd2000 if float).units (
float
, optional): length units to be used. Defaults to pk.AU.- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: the 3D axis.- Examples:
>>> import pykep as pk >>> ax = pk.plot.make_3Daxis() >>> pk.plot.add_sun(ax, label="Sun") >>> udpla = pk.udpla.jpl_lp(body="EARTH") >>> earth = pk.planet(udpla) >>> pk.plot.add_planet_orbit(ax, earth, plot_range = [0, 365.25], c = "royalblue", label = "") >>> pk.plot.add_planet(ax, earth, when = pk.epoch(0), c = "royalblue")
- pykep.plot.add_planet_orbit(ax, pla: planet, plot_range=None, units=149597870700.0, N=60, **kwargs)#
Adds a planet orbit to ax. All kwargs are forwarded to the plot method of ax.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): the 3D axis.pla (
planet
): the planet.plot_range (
list
, optional): the starting and end mjd2000 to be plotted. Defaults to [0., one_orbital_period] if a period can be computed.units (
float
, optional): length units to be used. Defaults to pk.AU.- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: the 3D axis.- Examples:
>>> import pykep as pk >>> ax = pk.plot.make_3Daxis() >>> pk.plot.add_sun(ax, label="Sun") >>> udpla = pk.udpla.jpl_lp(body="EARTH") >>> earth = pk.planet(udpla) >>> pk.plot.add_planet_orbit(ax, earth, plot_range = [0, 365.25], c = "royalblue", label = "") >>> pk.plot.add_planet(ax, earth, when = pk.epoch(0), c = "royalblue")
- pykep.plot.add_solar_system(ax, bodies=[1, 2, 3, 4, 5, 6], when=2000-01-01T00:00:00.000000, s=[15, 2, 3, 3, 2, 8, 8, 5, 5])#
Adds to ax the selected solar system planets.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): the 3D axis.bodies (
list
, optional): the solar system planet id (i.e. 3 for Earth). Defaults to [1, 2, 3, 4, 5, 6].when (
epoch
): the epoch.s (
list
, optional): the size of the Sun and all the 8 solar system planets. Defaults to [15, 2, 3, 3, 2, 8, 8, 5, 5].- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: the 3D axis.
Plotting trajectories#
- pykep.plot.add_lambert(ax, lp, N: int = 60, sol: int = 0, units=149597870700.0, **kwargs)#
Add Lambert’s problem solution trajectory to a 3D matplotlib Axes.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): The 3D Axes object to which the trajectory will be added.lp (
lambert_problem
): The Lambert’s problem object containing relevant information.N (
int
, optional): The number of points to generate along the trajectory. Default is 60.sol (
int
, optional): The solution index for Lambert’s problem. Default is 0.units (
float
, optional): The unit conversion factor for plotting. Default is _pk.AU.**kwargs: Additional keyword arguments to pass to the Axes3D.plot function.
- Raises:
ValueError: If the specified solution index (sol) is greater than twice the maximum number of revolutions (Nmax).
- Notes:
This function visualizes the trajectory of Lambert’s problem solution on the provided 3D Axes object. The trajectory is computed based on the initial and final positions, velocities, and gravitational parameter. The integration grid is defined based on the specified solution index and angle computations. The resulting trajectory is plotted on the given Axes object using the provided unit conversion factor.
- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: The modified Axes object with the Lambert’s problem trajectory added.
- pykep.plot.add_ballistic_arc(ax, rv0, tof, mu, units=149597870700.0, N=60, **kwargs)#
Add a ballistic trajectory arc to a 3D matplotlib Axes.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): The 3D Axes object to which the ballistic arc will be added.rv0 (
list
): Initial position and velocity vector in Cartesian coordinates.tof (
float
): Time of flight for the ballistic arc.mu (
float
): Gravitational parameter of the central body.units (
float
): The unit conversion factor for plotting. Default is pk.AU.N (
int
): The number of points to generate along the ballistic arc. Default is 60.**kwargs: Additional keyword arguments to pass to the Axes3D.plot function.
- Notes:
This function visualizes a ballistic trajectory arc on the provided 3D Axes object.
The trajectory is computed based on the initial position, velocity, time of flight, and gravitational parameter.
The resulting trajectory is plotted on the given Axes object using the provided unit conversion factor.
- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: The modified Axes object with the ballistic arc trajectory added.
- pykep.plot.add_sf_leg(ax, sf: _sims_flanagan, units=149597870700.0, N=10, show_midpoints=False, show_gridpoints=False, show_throttles=False, length=0.1, arrow_length_ratio=0.05, **kwargs)#
Add a trajectory leg of Sims-Flanagan problem to a 3D matplotlib Axes.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): The 3D Axes object to which the trajectory leg will be added.sf (
sims_flanagan
): The Sims-Flanagan object containing relevant information.units (
float
, optional): The unit conversion factor for plotting. Default is pk.AU.N (
int
, optional): The number of points to generate along each segment of the trajectory. Default is 10.show_midpoints (
bool
, optional): If True, midpoints of each segment are shown. Default is False.show_gridpoints (
bool
, optional): If True, gridpoints of the trajectory are shown. Default is False.show_throttles (
bool
, optional): If True, thrust vectors at midpoints are shown. Default is False.length (
float
, optional): The length of the thrust vectors when show_throttles is True. Default is 0.1.arrow_length_ratio (
float
, optional): The ratio of arrow length to the total length when show_throttles is True. Default is 0.05.**kwargs: Additional keyword arguments to pass to the Axes3D.plot function.
- Notes:
This function visualizes a Sims-Flanagan trajectory leg on the provided 3D Axes object.
Midpoints, gridpoints, and thrust vectors can be optionally shown based on the provided parameters.
- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: The modified Axes object with the Sims-Flanagan leg added.
- pykep.plot.add_sf_hf_leg(ax, sf: _sims_flanagan_hf, units=149597870700.0, N=10, show_gridpoints=False, show_throttles=False, show_throttles_tips=False, length=0.1, arrow_length_ratio=0.05, **kwargs)#
Add a trajectory leg of Sims-Flanagan problem to a 3D matplotlib Axes.
- Args:
ax (
mpl_toolkits.mplot3d.axes3d.Axes3D
): The 3D Axes object to which the trajectory leg will be added.sf (
sims_flanagan
): The Sims-Flanagan object containing relevant information.units (
float
, optional): The unit conversion factor for plotting. Default is pk.AU.N (
int
, optional): The number of points to generate along each segment of the trajectory. Default is 10. This translates to the grid_points_per_segment argument for retrieving the state history.show_gridpoints (
bool
, optional): If True, gridpoints of the trajectory are shown. Default is False.show_throttles (
bool
, optional): If True, thrust vectors at midpoints are shown. Default is False.show_throttles_tips (
bool
, optional): If True, and show_throttles is True, thrust vectors at midpoints are shown with an endline. Default is False.length (
float
, optional): The length of the thrust vectors when show_throttles is True. Default is 0.1.arrow_length_ratio (
float
, optional): The ratio of arrow length to the total length when show_throttles is True. Default is 0.05.**kwargs: Additional keyword arguments to pass to the Axes3D.plot function.
- Notes:
This function visualizes a Sims-Flanagan trajectory leg on the provided 3D Axes object.
Midpoints, gridpoints, and thrust vectors can be optionally shown based on the provided parameters.
- Returns:
mpl_toolkits.mplot3d.axes3d.Axes3D
: The modified Axes object with the Sims-Flanagan leg added.