Ask for better method to visualizing two-dimensional or three-dimensional areas

What’s the most recommended way to visualize a two-dimensional or three-dimensional areas, e.g., f(x, y) \leqslant c and f(x, y, z) \leqslant c ?

I’ve tried CairoMakie.contour but I’m not quite satisfied with it:

using CairoMakie

f(x, y) = x^2 + y^2
c = 3

## Method-1:
fig = Figure()
Axis(fig[1, 1])
xs = LinRange(-3, 3, 100)
ys = LinRange(-3, 3, 100)
zs = [f(x, y) for x in xs, y in ys]
contour!(xs, ys, zs, levels = [c], color=:red)
fig


## Method-2:
fig = Figure()
Axis(fig[1, 1])
xs = LinRange(-3, 3, 100)
ys = LinRange(-3, 3, 100)
zs = [f(x, y) for x in xs, y in ys]
contourf!(xs, ys, zs, levels = 2)
fig


I hope, for two-dimensional case, the area can be filled with some pure color and its border with another, and no color fills irrelevant area that f(x, y) > c.

For three-dimensional case, the surface of the area can be displayed, and the interior is not required to be filled with color, of course, it’ll be better if it is also fill with some color.

1 Like

Your question can be rephrased in more general terms: how to plot implicit functions?

There is some related discussion here:

1 Like