# 3D Graph with Domain contours

Hi

I would like to visualize in 3D the function below:

f_{X,Y}(x,y) = \begin{array}{ll} x^2, & \mbox{if $1 \leq x \leq 2$ and $0 \leq y \leq x$}, \ 0, & \mbox{otherwise}. \end{array} .

I execute this code below, but it is not displaying good (what is wrong with the code ?), and how to display the axes labels ?

var("x y z")
region = implicit_plot3d(z, (x, -3, 3), (y, -3, 3), (z, -3, 3) , plot_points=100, region=lambda x,y,z: x^2  and 1<x and x<2 and y<x and y>0,axes=True)
region.show()

edit retag close merge delete

I just edited the code, I just realized that I forgot y> 0 !. I added it now. it seems that only the contour of the x,y domain is displayed, but not the z contour.

Sort by » oldest newest most voted

Here are two ways to get the plot you want, one with vertical walls, one without.

If you don't mind the walls, define a function that is $x^2$ where you want and $0$ elsewhere. Then plot it.

sage: f = lambda x, y: x^2 if 1 <= x <= 2 and 0 <= y <= x else 0
sage: p = plot3d(f, (-3, 3), (-3, 3), plot_points=100)
sage: p.show(aspect_ratio=1, viewer='threejs')


If you prefer without walls, use the fact that Sage's 3D plotting functions plot nothing if they get something that evaluates to "not a number".

sage: nan = float(NaN)
sage: f = lambda x, y: x^2 if 1 <= x <= 2 and 0 <= y <= x else nan
sage: g = lambda x, y: nan if 1 <= x <= 2 and 0 <= y <= x else 0
sage: qf = plot3d(f, (-3, 3), (-3, 3), plot_points=100)
sage: qg = plot3d(g, (-3, 3), (-3, 3), plot_points=100)
sage: q = qf+qg
sage: q.show(aspect_ratio=1, viewer='threejs')

more

thank you very much slelievre, the rendering of your second code is really superb !!