diff --git a/stonesoup/plotter.py b/stonesoup/plotter.py index e83dcf314..f406d2d07 100644 --- a/stonesoup/plotter.py +++ b/stonesoup/plotter.py @@ -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'], diff --git a/stonesoup/tests/test_plotter.py b/stonesoup/tests/test_plotter.py index 15665acf6..593bb11e4 100644 --- a/stonesoup/tests/test_plotter.py +++ b/stonesoup/tests/test_plotter.py @@ -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()