Overlay rotated Images on plot with Matplotlib

Viewed 1356

I've currently constructed a plot using rectangle Patches to display a sequence of positions.

Plot of sequence

EDIT: Code used to generate this (built off of the RLPy library)-

def visualize_trajectory(self, trajectory=[[0,0,0,0], [0.1,0.1,0,0]]):
    domain_fig = plt.figure()

    for i, s in enumerate(trajectory):
        x, y, speed, heading = s[:4]
        car_xmin = x - self.REAR_WHEEL_RELATIVE_LOC
        car_ymin = y - self.CAR_WIDTH / 2.

        car_fig = matplotlib.patches.Rectangle(
            [car_xmin,
             car_ymin],
            self.CAR_LENGTH,
            self.CAR_WIDTH,
            alpha=(0.8 * i) / len(trajectory) )
        rotation = Affine2D().rotate_deg_around(
            x, y, heading * 180 / np.pi) + plt.gca().transData
        car_fig.set_transform(rotation)
        plt.gca().add_patch(car_fig)

Is there any way to overlay each of these patches with images? Ideally, there would be a car image instead of a rectangle at each of the positions.

I've played around with AnnotationBbox and TransformedBbox, but both seem to be inflexible when dealing with rotations.

1 Answers
Related