Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trajectories are not redrawn when the frame is changed #518

Closed
Juanlu001 opened this Issue Dec 28, 2018 · 5 comments

Comments

2 participants
@Juanlu001
Copy link
Member

Juanlu001 commented Dec 28, 2018

馃悶 Problem

When OrbitPlotter.plot_trajectory is used and then the frame is changed, the orbits are redrawn but the trajectories aren't.

Compare:

frame = OrbitPlotter()

frame.plot(churi, label="churi", color="C1")
frame.plot(eros, label='eros', color="C0")
frame.plot_trajectory(rr_earth, label=Earth, color="C2");

with

frame = OrbitPlotter()

frame.plot(eros, label='eros', color="C0")
frame.plot(churi, label="churi", color="C1")
frame.plot_trajectory(rr_earth, label=Earth, color="C2")

frame.set_frame(*churi.pqw())
Without set_frame With set_frame
Without set_frame With set_frame

馃挕 Possible solutions

Only full orbits are stored in the OrbitPlotter, but not trajectories:

def plot_trajectory(self, trajectory, *, label=None, color=None):
"""Plots a precomputed trajectory.
Parameters
----------
trajectory : ~astropy.coordinates.BaseRepresentation, ~astropy.coordinates.BaseCoordinateFrame
Trajectory to plot.
"""
lines = []
rr = trajectory.represent_as(CartesianRepresentation).xyz.transpose()
x, y = self._project(rr)
a, = self.ax.plot(
x.to(u.km).value, y.to(u.km).value, "--", color=color, label=label
)
lines.append(a)
if label:
a.set_label(label)
self.ax.legend(
loc="upper left", bbox_to_anchor=(1.05, 1.015), title="Names and epochs"
)
return lines

Therefore, trajectories are lost on redraw:

def _redraw(self):
for artist in self.ax.lines + self.ax.collections:
artist.remove()
self._attractor = None
for orbit, label, color in self._orbits:
self.plot(orbit, label, color)
self.ax.relim()
self.ax.autoscale()

馃搵 Steps to solve the problem

  • Comment below about what you've started working on.
  • Add, commit, push your changes
  • Submit a pull request and add this in comments - Addresses #<put issue number here>
  • Ask for a review in comments section of pull request
  • Celebrate your contribution to this project 馃帀
@shreyasbapat

This comment has been minimized.

Copy link
Member

shreyasbapat commented Jan 1, 2019

Adding a trajectory list is enough?

@Juanlu001

This comment has been minimized.

Copy link
Member Author

Juanlu001 commented Jan 1, 2019

Should be!

@shreyasbapat

This comment has been minimized.

Copy link
Member

shreyasbapat commented Jan 1, 2019

There might be two solutions to this:

  1. Renaming orbits to trajectories list and moving it to plot_trajectory completely
  2. Adding an extra Parameter in plot_trajectory which checks if it is being called independently or inside OrbitPlotter,plot and appending only independent calles to trajectories

What do you suggest?

@Juanlu001

This comment has been minimized.

Copy link
Member Author

Juanlu001 commented Jan 2, 2019

Adding an extra Parameter in plot_trajectory which checks if it is being called independently or

Don't like it :)

@Juanlu001

This comment has been minimized.

Copy link
Member Author

Juanlu001 commented Jan 4, 2019

I'm in the process of refactoring the whole plotting module, so I will take care of this myself.

@Juanlu001 Juanlu001 self-assigned this Jan 4, 2019

@Juanlu001 Juanlu001 added this to the 0.12 milestone Jan 4, 2019

@Juanlu001 Juanlu001 referenced this issue Jan 4, 2019

Merged

Refactor plotting #528

6 of 8 tasks complete

Juanlu001 added a commit to Juanlu001/poliastro that referenced this issue Jan 7, 2019

Juanlu001 added a commit to Juanlu001/poliastro that referenced this issue Jan 7, 2019

Juanlu001 added a commit to Juanlu001/poliastro that referenced this issue Jan 7, 2019

@Juanlu001 Juanlu001 closed this in b74bd1d Jan 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.