'How to plot a surface over a constrained domain with matplotlib?

I want to plot a surface over a constrained domain. For example, the domain is a parallelogram with four vertices (0,0),(1,1),(2,0),(3,1), and the surface is z=x+y, here is my code:

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

y = np.linspace(0, 1, 30)
x0 = y
x = np.linspace(x0, 2+x0 , 30)

X, Y = np.meshgrid(x, y)
Z = X+Y


fig = plt.figure(figsize=(7, 3))
ax = plt.axes(projection='3d')
ax.plot_wireframe(X, Y, Z)
plt.show()

I know the variable x and y represent a list in python, but I don't know how to adjust the range of them when I want to plot a surface because the range of x is depend on the value of y. I would appreciate it if you could provide some details.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source