import matplotlib.pyplot as plt from matplotlib.collections import LineCollection from tutorial import track_loader tracks = track_loader('polygons.shp') # Filter out non-tracks (unassociated polygons given trackID of -9) tracks = {tid: t for tid, t in tracks.items() if tid != -9} fig, ax = plt.subplots(1, 1) lc = LineCollection(tracks.values(), color='b') ax.add_collection(lc) ax.autoscale(True) ax.set_xlabel("Longitude") ax.set_ylabel("Latitude") plt.show()
import matplotlib.pyplot as plt from matplotlib.lines import Line2D from matplotlib.patches import Polygon from tutorial import track_loader, polygon_loader tracks = track_loader('polygons.shp') polygons = polygon_loader('polygons.shp', group='frame_index') fig, ax = plt.subplots(1, 1) for trkid, trk in tracks.items(): x, y = zip(*trk) if trkid == -9: ax.scatter(x, y, color='r') else: ax.add_artist(Line2D(x, y, color='b', picker=2, lw=1)) poly_objs = [] for frame in sorted(polygons): frame_polys = [] for poly in polygons[frame]: p = Polygon(poly, lw=3, fc='k', zorder=1, ec='k', alpha=0.45, visible=(not frame)) ax.add_artist(p) frame_polys.append(p) poly_objs.append(frame_polys)