Skip to main content

SumoNetVis

A Python library for visualizing a Sumo network and trajectories with matplotlib.

Example plot of an intersection with trajectory colored by speed Example plot of an curving road with bike lanes Example animation

Basic trajectory plotting from FCD outputs is built in, but it is also possible to plot custom data and graphics on top of the network with the full flexibility and power of matplotlib and other compatible libraries, such as seaborn.

Installation

This package can be installed via pip with the command pip install SumoNetVis. You can then import the library with:

import SumoNetVis

Dependencies

  • shapely
  • matplotlib
  • numpy

Usage

To plot a Sumo net file and trajectories, you can use the following code:

import SumoNetVis
import matplotlib.pyplot as plt
# Plot Sumo Network
net = SumoNetVis.Net("path/to/yourfile.net.xml")
net.plot()
# Plot trajectories
trajectories = SumoNetVis.Trajectories("path/to/fcd-output.xml")
trajectories["vehicle_id"].assign_colors_speed()
trajectories["vehicle_id"].plot()
# Show figure
plt.show()

You also have the option of passing a matplotlib Axes object to the plot methods.

Animation

Instead of visualizing Trajectories as lines, an animation can be generated using the matplotlib.animation module.

import matplotlib.animation as animation
trajectories = SumoNetVis.Trajectories("path/to/fcd-output.xml")
fig, ax = plt.subplots()
a = animation.FuncAnimation(fig, trajectories.plot_points, frames=trajectories.timestep_range(), repeat=False,
                            interval=1000*trajectories.timestep, fargs=(ax,), blit=True)
plt.show()

The plot settings for each vehicle can be customized and the color of each point can be animated, as shown in the following example.

for trajectory in trajectories:
        trajectory.assign_colors_speed()
        trajectory.point_plot_kwargs["ms"] = 8  # set marker size. Can set any kwargs taken by matplotlib.pyplot.plot().

In order to animate the color of the points based on the assigned color scheme, an additional farg must be passed when creating the animation.

a = animation.FuncAnimation(fig, trajectories.plot_points, frames=trajectories.timestep_range(), repeat=False,
                            interval=1000*trajectories.timestep, fargs=(ax, True), blit=True)

Contribution

Issues and pull requests are welcome.

Metadata

Release files for SumoNetVis 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SumoNetVis 1.1.0
File Size Uploaded
SumoNetVis-1.1.0.tar.gz 8.5 kB Details

Release files / SumoNetVis-1.1.0.tar.gz

Download URL SumoNetVis-1.1.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
908439f410b9e16ae0e8cd833b0e9098d9055413e49c028edd4247611e92a153
BLAKE2b-256 checksum
How to use checksums
c795090634a5a60eee0c7e34134091e60fe54710a66a7e451dcb809b19295940
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.9

Release history Release notifications | RSS feed

1.6.2

1 release file

1.6.1

1 release file

1.6.0

1 release file

1.5.2

1 release file

1.5.1

1 release file

1.5.0

1 release file

1.4.4

1 release file

1.4.3

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

This release

1.1.0 This release

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page