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
astrojuanlu opened this issue Dec 28, 2018 · 5 comments
Closed

Trajectories are not redrawn when the frame is changed #518

astrojuanlu opened this issue Dec 28, 2018 · 5 comments
Assignees
Milestone

Comments

@astrojuanlu
Copy link
Member

@astrojuanlu astrojuanlu 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
Copy link
Member

@shreyasbapat shreyasbapat commented Jan 1, 2019

Adding a trajectory list is enough?

@astrojuanlu
Copy link
Member Author

@astrojuanlu astrojuanlu commented Jan 1, 2019

Should be!

@shreyasbapat
Copy link
Member

@shreyasbapat 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?

@astrojuanlu
Copy link
Member Author

@astrojuanlu astrojuanlu commented Jan 2, 2019

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

Don't like it :)

@astrojuanlu
Copy link
Member Author

@astrojuanlu astrojuanlu commented Jan 4, 2019

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

@astrojuanlu astrojuanlu self-assigned this Jan 4, 2019
@astrojuanlu astrojuanlu added this to the 0.12 milestone Jan 4, 2019
@astrojuanlu astrojuanlu mentioned this issue Jan 4, 2019
8 tasks
astrojuanlu added a commit to astrojuanlu/poliastro that referenced this issue Jan 7, 2019
astrojuanlu added a commit to astrojuanlu/poliastro that referenced this issue Jan 7, 2019
astrojuanlu added a commit to astrojuanlu/poliastro that referenced this issue Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants