Skip to content

Commit

Permalink
Merge pull request #675 from dstl/zero_track_plot_fix
Browse files Browse the repository at this point in the history
Fix Plotter raising error when no tracks available to plot
  • Loading branch information
sdhiscocks committed Jul 19, 2022
2 parents 8e7f596 + d4ae4af commit 06c01e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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()

0 comments on commit 06c01e9

Please sign in to comment.