0
Z=np.array([[10.,12.,12.,5.],
        [10.,0.,0.,5.],
        [10.,0.,0.,5.],
        [10.,20.,20.,20.]])
X = np.arange(0, 4, 1)
Y = np.arange(0, 4, 1)

I have a 2D 4x4 array with. I want to make a 3D plot with x and y axes having discrete integer values from 0 to 4. Can someone help me with that?

Serenity
  • 35,289
  • 20
  • 120
  • 115

1 Answers1

0

you first need to make 2D arrays of your X,Y vectors:

import numpy as np
X2D,Y2D = np.meshgrid(X,Y)

then you can use a surface plot (or wireframe):

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = Axes3D(fig)

ax.plot_surface(X2D,Y2D, Z)

the axis will can only be 0 to 3 if you only have 4 points (you need 5 to go from 0 to 4)

kosack
  • 152
  • 1
  • 5