import numpy as np
import matplotlib. pyplot as plt
from mpl_toolkits. mplot3d import Axes3D
x = np. arange( 0 , 3 , 0.5 )
y = np. arange( - 5 , 2 , 1 )
print ( x)
print ( y)
[0. 0.5 1. 1.5 2. 2.5]
[-5 -4 -3 -2 -1 0 1]
X, Y = np. meshgrid( x, y)
print ( X. shape)
print ( Y. shape)
(7, 6)
(7, 6)
print ( X)
print ( ' ' )
print ( Y)
[[0. 0.5 1. 1.5 2. 2.5]
[0. 0.5 1. 1.5 2. 2.5]
[0. 0.5 1. 1.5 2. 2.5]
[0. 0.5 1. 1.5 2. 2.5]
[0. 0.5 1. 1.5 2. 2.5]
[0. 0.5 1. 1.5 2. 2.5]
[0. 0.5 1. 1.5 2. 2.5]]
[[-5 -5 -5 -5 -5 -5]
[-4 -4 -4 -4 -4 -4]
[-3 -3 -3 -3 -3 -3]
[-2 -2 -2 -2 -2 -2]
[-1 -1 -1 -1 -1 -1]
[ 0 0 0 0 0 0]
[ 1 1 1 1 1 1]]
Z = ( X+ Y) ** 2
Z. shape
(7, 6)
fig = plt. figure( 'Z' )
ax = fig. gca( projection= '3d' )
ax. plot_surface( X, Y, Z)
plt. show( )