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

Fix Plotter raising error when no tracks available to plot #675

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions stonesoup/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ def plot_tracks(self, tracks, mapping, uncertainty=False, particle=False, track_
continue
track_colors[track] = plt.getp(line[0], 'color')

# Assuming a single track or all plotted as the same colour then the following will work.
# Otherwise will just render the final track colour.
tracks_kwargs['color'] = plt.getp(line[0], 'color')
if tracks: # If no tracks `line` won't be defined
# Assuming a single track or all plotted as the same colour then the following will
# work. Otherwise will just render the final track colour.
tracks_kwargs['color'] = plt.getp(line[0], 'color')

# Generate legend items for track
track_handle = Line2D([], [], linestyle=tracks_kwargs['linestyle'],
Expand Down
5 changes: 5 additions & 0 deletions stonesoup/tests/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@ def test_plot_sensors():
plotter3d.plot_sensors(sensor, marker='o', color='red')
plt.close()
assert 'Sensor' in plotter3d.legend_dict


def test_empty_tracks():
plotter.plot_tracks(set(), [0, 2])
plt.close()