1

I'm trying to get two subplots of different kind. The first should show an image (colormap) of the data, the second a surface plot of the same data. Independently, both plots work fine, but if i want to combine them into one figure, it fails with the error: AttributeError: 'AxesSubplot' object has no attribute 'plot_surface'

Here is my code

fig, (ax1, ax2)  = plt.subplots(nrows=1, ncols=2, figsize=(20, 6))
#fig, ax = plt.subplots(nrows=1, ncols=2, subplot_kw={'projection': '3d'}, figsize=(20, 6))


surf1 = ax1.imshow(I[:,:,250], cmap=plt.cm.YlGnBu_r)
surf2 = ax2.plot_surface(X[:,:,0], Y[:,:,0], loaded_profile,  cmap=plt.cm.YlGnBu_r,linewidth=0, antialiased=False)
ax[0].set_xlabel(r'$\phi_\mathrm{real}$')

show()

I'm using jupyter notebook and python 3.6 Where is my error?

Simon
  • 53
  • 5
  • `plot_surface` is a method of the 3D axes `matplotlib.axes._subplots.Axes3DSubplot`, so it is not available from a normal `matplotlib.axes._subplots.AxesSubplot`. You need to create a 3D axes first, just as shown e.g. in [the official example](https://matplotlib.org/devdocs/gallery/mplot3d/mixed_subplots.html). – ImportanceOfBeingErnest Dec 04 '17 at 16:03

0 Answers0