Ask Your Question

Revision history [back]

If I understand correctly, the goal is to produce a 3d plot of a function of two variables, with some partial functions plotted on top of it.

The partial plots, or plots of the partial functions, are supposed to be inserted vertically at the relevant x or y values; in other words we want to visualize the intersections of the 3d plot with some vertical planes corresponding to a few particular values of x, and of y.

Here is one way this can be achieved.

Pick a function f of two variables to plot:

sage: f = lambda x, y: x^2 + sqrt(y)

Pick the x-range and the y-range:

sage: x_xx = (-3.1, 3.1)
sage: y_yy = (0, 6)

Define the 3d-plot with partial opacity.

sage: P = plot3d(f, x_xx, y_yy, color='red', alpha=0.25)

To plot partial functions of f, we will use:

sage: Px = lambda x: parametric_plot((lambda t: x, lambda t: t, lambda t: f(x, t)), y_yy)
sage: Py = lambda y: parametric_plot((lambda t: t, lambda t: y, lambda t: f(t, y)), x_xx)

Define a new graphics object G that initially is P and add the desired partial plots to it:

sage: G = P
sage: for x in (-3 .. 3):
....:     G += Px(x)
sage: for y in (0 .. 6):
....:     G += Py(y)

View the result (choices for the viewer include 'jmol', 'tachyon', 'threejs'):

sage: G.show(viewer='threejs')