I'm trying to plot a 3D shape with a 2D image overlaying the xy-plane. I've only just started working with python, so this is more challenging than it ought to be.
This question here addresses what I am trying to do : Image overlay in 3d plot using python. But when I run the provided code I get the following error:
File "test.py", line 13, in <module>
ax.plot_surface(x, y, 10, rstride=5, cstride=5, facecolors=img)
File "/usr/lib64/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 663, in plot_surface
rows, cols = Z.shape
AttributeError: 'int' object has no attribute 'shape'
The image I am using is stored in the same folder as my 'test.py.' The question I referenced above uses an image from get_sample_data, but if I edit it to use my image, the code is as follows:
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
from matplotlib._png import read_png
img = read_png('milkyway.png')
x, y = ogrid[0:img.shape[0], 0:img.shape[1]]
ax = gca(projection='3d')
ax.plot_surface(x, y, 10, rstride=5, cstride=5, facecolors=img)
show()
I get the same error whether I use get_sample_data or my own image. Any suggestions of what I can change? Thanks!