Is there a way to plot an image file on a 3D graph surface using Python?
I have seen a couple of ways of plotting this as a plane but I would like the image to drape over the surface of the plot. Is this possible?
You need to change the color of your surface to be the color of the image as in this example suggested by @sarwar.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.cbook import get_sample_data
from matplotlib._png import read_png
import numpy as np
fn = get_sample_data("lena.png", asfileobj=False)
img = read_png(fn)
x, y = np.mgrid[0:img.shape[0], 0:img.shape[1]]
ax = plt.gca(projection='3d')
ax.plot_surface(x, y, np.sin(0.02*x)*np.sin(0.02*y), rstride=2, cstride=2,
facecolors=img)
plt.show()
That gives as result
Take a look at the answer to this question. They use a fixed z, but you could substitute that with your topographic data to get the desired effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With