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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph route animations #1187

Open
3 tasks done
nkleinbaer opened this issue Jun 22, 2024 · 5 comments
Open
3 tasks done

Graph route animations #1187

nkleinbaer opened this issue Jun 22, 2024 · 5 comments

Comments

@nkleinbaer
Copy link

Contributing guidelines

  • I understand the contributing guidelines

Documentation

  • My proposal is not addressed by the documentation or examples

Existing issues

  • Nothing similar appears in an existing issue

What problem does your feature proposal solve?

Allow users to create animated plots of routes on graphs. For routes that cover all or most edges of a graph, a static plot doesn't show the route very clearly.

What is your proposed solution?

Use matplotlib.animations.FuncAnimation to animate route(s) step-by-step.
Either:

  1. Add a new osmnx.plot.animate_graph_route function for this feature
  2. Add animate: bool argument to the existing osmnx.plot.plot_graph_route function

What alternatives have you considered?

Of course users can implement this themselves outside of osmnx, not sure if this passes the "not trivially easy" criteria from contributing guidelines.

Additional context

I've been using osmnx for a toy project looking at the route inspection problem. Huge thanks for this awesome project, made it easy for me to get started playing with the actual problem quickly instead of writing code to fetch road data and convert it into graphs. For my use case I found that plotting the entire route at once isn't particularly insightful -- my routes always cover the entire graph -- so I implemented animation for myself. Figured it may be useful to others and worth contributing back.

I've technically made a liar of myself by checking the "Nothing similar appears in an existing issue" box. I see two old, closed issues mentioning animation:

In #226 the animation piece is only mentioned tangentially, in #109 a user asks for help doing this but doesn't explicitly propose/request a feature.

Can post a brief code snippet with minimal example a bit later today.

@gboeing
Copy link
Owner

gboeing commented Jun 24, 2024

Thanks for using OSMnx and suggesting this.

Can post a brief code snippet with minimal example a bit later today.

Sure, would you post the proposed code and I'll take a look?

Of course users can implement this themselves outside of osmnx, not sure if this passes the "not trivially easy" criteria from contributing guidelines.

It's really just a matter of the complexity of the proposed code. Sometimes it's just easier to share a dozen lines of code here in a comment or on StackOverflow for others to reuse than it is to incorporate it into the package, depending on the general applicability of the use case.

@nkleinbaer
Copy link
Author

nkleinbaer commented Jun 25, 2024

Here is a minimal example, taking the route of adding on to the existing plot_graph_route func.

I found it convenient to define update_lines as an inner function so that it could just modify the lines variable defined in the outer scope, but alternatively this could be passed using the functools.partial or by passing fargs to matplotlib.animation.FuncAnimation (although the docs say the later is discouraged).

To make it a bit snazzier I've also played around with:

  1. Increasing the alpha on all but the leading line segment so that the "trail" left by the route appears faded out. This makes it easier to view routes that double-back on themselves
  2. Advancing one full graph edge at a time (currently just goes vertex-by-vertex)
  3. Or, alternatively, interpolating additional vertices along the route to make it look smoother

@gboeing
Copy link
Owner

gboeing commented Jul 5, 2024

Interesting idea. It seems better to create a new function like animate_graph_route to keep the API a little cleaner and allow for future enhancement to animation parameters. Do you want to do some refining to get it to a proposed state you like and then open a PR for discussion?

@jabahm
Copy link

jabahm commented Nov 20, 2024

Thank you, @nkleinbaer, for this excellent proposal and @gboeing for the constructive feedback. The idea of animating graph routes is incredibly valuable, especially for visualizing complex paths that cover a significant portion of the graph. It would be a fantastic addition to OSMnx.

I have a few suggestions that might enhance this feature:
Adjustable animation speed: Allow users to control the playback speed based on the route's length.
Export options: Include the ability to export the animation as a video or GIF for presentations and reports.

If there's interest, I'd be more than happy to contribute to the development.

@nkleinbaer
Copy link
Author

nkleinbaer commented Nov 20, 2024

Hey @Ahmed-Jabrane glad to hear someone else thinks this would be useful. And thanks for bumping this -- I missed @gboeing's reply and let this fall off my radar, sorry about that Geoff. I'll revisit it this this week and get a PR open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants