Exemplo n.º 1
0
    def _plot_body_orbit(
        self,
        body,
        epoch,
        *,
        label=None,
        color=None,
        trail=False,
    ):
        if color is None:
            color = BODY_COLORS.get(body.name)

        self.set_attractor(body.parent)

        # Get approximate, mean value for the period
        period = get_mean_elements(body, epoch).period

        label = generate_label(epoch, label or str(body))
        epochs = time_range(epoch,
                            periods=self._num_points,
                            end=epoch + period,
                            scale="tdb")
        ephem = Ephem.from_body(body,
                                epochs,
                                attractor=body.parent,
                                plane=self.plane)

        return self._plot_ephem(ephem,
                                epoch,
                                label=label,
                                color=color,
                                trail=trail)
Exemplo n.º 2
0
    def plot(self, orbit, *, label=None, color=None, trail=False):
        """Plots state and osculating orbit in their plane.

        Parameters
        ----------
        orbit : ~poliastro.twobody.orbit.Orbit
            Orbit to plot.
        label : string, optional
            Label of the orbit.
        color : string, optional
            Color of the line and the position.
        trail : bool, optional
            Fade the orbit trail, default to False.

        """
        colors = self._get_colors(color, trail)

        self.set_attractor(orbit.attractor)
        self._set_plane(orbit.plane, fail_if_set=False)

        label = generate_label(orbit, label)
        positions = orbit.change_plane(self._plane).sample(self._num_points)

        self._plot(positions, orbit.r, label, colors)

        self._trajectories.append(
            Trajectory(positions, orbit.r, label, colors[0]))
Exemplo n.º 3
0
    def _set_legend(self, epoch, label):
        label = generate_label(epoch, label)
        if not self._ax.get_legend():
            size = self._ax.figure.get_size_inches() + [8, 0]
            self._ax.figure.set_size_inches(size)

        self._ax.legend(
            loc="upper left",
            bbox_to_anchor=(1.05, 1.015),
            title=label,
            numpoints=1,
        )
Exemplo n.º 4
0
    def _plot(self, orbit, *, label=None, color=None, trail=False):
        colors = self._get_colors(color, trail)

        self.set_attractor(orbit.attractor)

        orbit = orbit.change_plane(self.plane)

        label = generate_label(orbit.epoch, label)
        coordinates = orbit.sample(self._num_points)

        return self.__add_trajectory(
            coordinates, orbit.r, label=label, colors=colors, dashed=True
        )
Exemplo n.º 5
0
    def plot(self, orbit, label=None, color=None):
        """Plots state and osculating orbit in their plane.
        """
        if not self._frame:
            self.set_frame(*orbit.pqw())

        self.set_attractor(orbit.attractor)
        self._redraw_attractor(orbit.r_p * 0.15)  # Arbitrary threshold
        positions = orbit.sample(self.num_points)
        if label:
            label = generate_label(orbit, label)

        lines = self._plot(positions, orbit.r, label, color)

        self._trajectories.append(
            Trajectory(positions, orbit.r, label, lines[0].get_color()))
        return lines
Exemplo n.º 6
0
    def plot(self, orbit, label=None, color=None, method=mean_motion):
        """Plots state and osculating orbit in their plane.
        """
        if not self._frame:
            self.set_frame(*orbit.pqw())

        self.set_attractor(orbit.attractor)
        self._redraw_attractor(orbit.r_p * 0.15)  # Arbitrary threshold
        positions = orbit.sample(self.num_points, method=method)
        if label:
            label = generate_label(orbit, label)

        lines = self._plot(positions, orbit.r, label, color)

        self._trajectories.append(
            Trajectory(positions, orbit.r, label, lines[0].get_color())
        )
        return lines
Exemplo n.º 7
0
    def plot(self, orbit, *, label=None, color=None):
        """Plots state and osculating orbit in their plane.

        Parameters
        ----------
        orbit : ~poliastro.twobody.orbit.Orbit
            Orbit to plot.
        label : string, optional
            Label of the orbit.
        color : string, optional
            Color of the line and the position.

        """
        if color is None:
            color = next(self._color_cycle)

        self._set_attractor(orbit.attractor)

        label = generate_label(orbit, label)
        trajectory = orbit.sample()

        trace = self._plot_trajectory(trajectory, label, color, True)

        self._trajectories.append(
            Trajectory(trajectory, orbit.r, label, trace.line.color)
        )

        # Redraw the attractor now to compute the attractor radius
        self._redraw_attractor()

        # Plot required 2D/3D shape in the position of the body
        radius = min(
            self._attractor_radius * 0.5, (norm(orbit.r) - orbit.attractor.R) * 0.5
        )  # Arbitrary thresholds
        self._plot_point(radius, color, label, center=orbit.r)

        if not self._figure._in_batch_mode:
            return self.show()