Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I would also like to know true-sage approach, just in case here is a clumsy approach with loops and matplotlib:

import numpy as np

import matplotlib
import matplotlib.pyplot as plt

from matplotlib.pyplot import figure
from mpl_toolkits.mplot3d import axes3d

# Define

def f(x, y):
    if not (-y <= x <= y):
        return 0
        return x ** 2 + y ** 2

# Calculate

N = 512

y = np.linspace(0, 3, N)
x = np.linspace(-3, 3, N)

z = np.zeros((N, N))

for i, _x in enumerate(x):
    for j, _y in enumerate(y):
        z[i, j] = f(_x, _y)

# Plot

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(x, y)
ax.plot_surface(X, Y, z)

image description