0

I have two 2D arrays and I want to use to produce an image similar to the one that fallows, just with different limits on the axis.

enter image description here

Here is my attempt so far:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlim(-2.01, 2.01)
ax.set_ylim(-2.01, 2.01)
ax.set_zlim(-2.01, 2.01)
cmap = plt.cm.gray
im = ax.imshow(np.asarray(array1), cmap=cmap)
im.remove()
fig.colorbar(im)
plt.show()

The arrays I have, (array1 and array2) are two dimensional with sizes n by n. Any help or a point in the right direction will be greatly appreciated!

user906357
  • 4,575
  • 7
  • 28
  • 38

1 Answers1

1

With help of Matplotlib - Plot a plane and points in 3D simultaneously, I am able to achieve this:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)

ax.set_xticks([0, 0.2, 0.4, 0.6, 0.8, 1])
ax.set_yticks([0, 0.5, 1])
ax.set_zticks([0, 0.2, 0.4, 0.6, 0.8, 1])
cmap = plt.cm.gray

#plot vertical surface
y = 0.5
xx, zz = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10))
p = ax.plot_surface(xx, y, zz, cmap=cmap, alpha=0.5)

x = 0.2
yy, zz = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10))
p = ax.plot_surface(x, yy, zz, cmap=cmap, alpha=0.5)

fig.colorbar(p)
plt.show()

Note that I didn't use normal or dot just as another question do, because here you want to plot vertical planes.

Here's what I got(I'm working on the right occlusion):

enter image description here

keineahnung2345
  • 2,635
  • 4
  • 13
  • 28
  • Maybe I should ask this as another thread, but how do I add the data from array1 to p = ax.plot_surface(xx, y, zz, cmap=cmap, alpha=0.5)? – user906357 Feb 14 '19 at 17:22
  • @user906357 https://stackoverflow.com/questions/32413371/color-of-a-3d-surface-plot-in-python This should be helpful. – keineahnung2345 Feb 17 '19 at 04:50