Sibbs Gambling
Sibbs Gambling

Reputation: 20345

Insert a Picture as the Background of a Figure?

I wish to draw some pedestrian trajectories given the coordinates of every point on the trajectories. This can be easily done using matplotlib.

But in my case, the trajectories mean nothing if they are simply drawn over a blank background. They will only make sense when I overlay them on the real floor map such as the one below.

enter image description here

So I am wondering whether it is possible to make my floor map as the background of the figure, and then draw the points and trajectories over it?

Upvotes: 1

Views: 110

Answers (1)

Joe Kington
Joe Kington

Reputation: 284582

Sure, just plot the map with imshow and then plot your lines on top of it.

For example:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(500) + 100
y = 50 * np.cos(x / 10.0) + 100

fig, ax = plt.subplots()

ax.imshow(plt.imread('floor_plan.gif'), origin='lower')
ax.autoscale(False)
ax.plot(x, y)

plt.show()

enter image description here

Upvotes: 3

Related Questions