2

I am trying to understand a problem-set which involves cartesian planes where:

f(x, y) = min(x, y)
g(x, y) = max(x, y)
h(x, y) = x + y

For this reason I was trying to plot the given functions using python and matplotlib like this:

data_x_axis = list(range(11))
data_y_axis = list(range(11))
data_z_axis = []

for x_value in data_x_axis:
    data_z_axis.append([min(x_value, y_value) for y_value in data_y_axis])

print(data_z_axis)


%matplotlib notebook
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Grab some test data.
X = data_x_axis
Y = data_y_axis
Z = np.array(data_z_axis)

# Plot a basic wireframe.
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()

In essence this is the example code from: https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#wireframe-plots

x,y values ranging from 0 to 10, z being computet as min(x,y).

However the result was this:

enter image description here

My math is beyond rusty, but I was expecting a surface area, not a two dimensional triangle.

Is my understanding of the underlying math wrong or did I make a mistake in computing the values/plotting them in matplotlib?

Ryan Walker
  • 3,176
  • 1
  • 23
  • 29
MrTony
  • 264
  • 1
  • 12

1 Answers1

3

They should be surfaces. Your math is right.

Unfortunately, you're plotting two 1-dimensional arrays instead of a 2D array:

data_x_axis = list(range(11))
data_y_axis = list(range(11))
X = data_x_axis
Y = data_y_axis
ax.plot_wireframe(X, Y, ....

which just gives you 11 points to plot.

Try this:

  1. Make an array for the X and Y values
  2. Use those coordinates (pairs) to calculate Z
  3. Associate each Z with a pair: (X, Y)
  4. Now plot the triples (X, Y, Z)
David Collins
  • 848
  • 3
  • 10
  • 28