# GLMakie: plot surface and nonlinear constraints

Hi,
I’m plotting the surface of a function (the objective function of an optimization problem) with this code:

``````using GLMakie
let
# range
x = LinRange(-2, 0.5, 51)
y = LinRange(-2, 2, 51)
# objective function
z = 100 .* (y' .- x .^ 2) .^ 2 .+ (1 .- x) .^ 2

zmin, zmax = minimum(z), maximum(z)
cmap = :greens
fig = Figure(resolution = (900,900))
ax = Axis3(fig, perspectiveness = 0.5, elevation = π/9,
zgridcolor = :grey, ygridcolor = :grey, xgridcolor = :grey)
surface!(ax, x, y, z, colormap = cmap, colorrange = (zmin, zmax))
fig[1,1] = ax
fig
end
``````

found here.

I’d like to portray the nonlinear constraints of the problem as well, for example:
x*y >= 1
x + y^2 >= 0
by e.g. displaying the infeasible points with a different color (throwing them out altogether wouldn’t help a lot for the visualization).
I don’t know if Makie supports that natively, or if I need to filter the LinRanges and display 2 surfaces. Can you help me out?
Best,

Charlie

Color accepts `Matrix{Float}` and `Matrix{<:Colorant}`, which should make that possible!

I think its not as easy as to pass a colour matrix. At least I didn’t see how to do it. It’s not possible to use colorrange, and clips, because the regions of interest are not constant. Well, this is my attempt at the problem.

https://lazarusa.github.io/BeautifulMakie/surfWireLines/surfaceConstraints/

3 Likes

What’s happening on the right edge?

Thanks a lot (even with the funny axis label )!