Here’s a quick one.
Problem.
You want to add pretty graphics in the back of your data. How to do this with matplotlib?
Solution
import numpy as np
import matplotlib.pyplot as plt
# Path to the image
fpath =r"C:\Users\sukhbinder.singh\Desktop\day.jpg"
# Read the image
img = plt.imread(fpath)
# Plot the image
fig, ax = plt.subplots()
ax.imshow(img)
a, b, c,d = plt.axis('off')
# Now plot your appropriatly scalled data. We will plot some
# random numbers
xx = np.random.randint(a,b, size=100)
yy = np.random.randint(d,c, size=100)
plt.plot(xx,yy, "r.")
plt.savefig("wall.png")
plt.show()
Simple. Here’s the result
