# GLMakie: plot surface and nonlinear constraints

**URL:** <https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619>\
**Category:** Visualization\
**Tags:** glmakie\
**Created:** [June 9, 2021, 11:58am UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619 "2021-06-09T11:58:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [June 9, 2021, 11:58am UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/1 "2021-06-09T11:58:45Z")

</div>

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

```julia
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](https://lazarusa.github.io/BeautifulMakie/surfWireLines/surfWireContour/).

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

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 9, 2021, 12:01pm UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/2 "2021-06-09T12:01:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [June 9, 2021, 3:25pm UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/3 "2021-06-09T15:25:20Z")

</div>

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/](https://lazarusa.github.io/BeautifulMakie/surfWireLines/surfaceConstraints/)

 ![surfaceConstraints](https://global.discourse-cdn.com/julialang/original/3X/9/f/9f8937d50661716fed315dfb06b5c95ca04d2e24.png)

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [June 9, 2021, 9:15pm UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/4 "2021-06-09T21:15:20Z")

</div>

What’s happening on the right edge?

![image](https://global.discourse-cdn.com/julialang/original/3X/e/e/ee7837ff482b3ff5e91d923e736e52d5f9150119.png)

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [June 9, 2021, 9:32pm UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/5 "2021-06-09T21:32:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olegg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegg/32/51316_2.png) [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Post date:** [August 30, 2023, 5:52pm UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/6 "2023-08-30T17:52:41Z")

</div>

This looks great and super useful. Unfortunately, the link is dead …

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [August 30, 2023, 9:36pm UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/7 "2023-08-30T21:36:12Z")

</div>

is here:

> **[constraints - Beautiful Makie](https://beautiful.makie.org/dev/examples/generated/2d/surfaces/constraints/)**
>
> Makie Examples

but, I’m afraid it will change soon again. Hopefully, in this iteration things will be more stable over a longer period of time.

---

<div class="post-metadata">

**Author:** ![Olegg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegg/32/51316_2.png) [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Post date:** [August 31, 2023, 7:16am UTC](https://discourse.julialang.org/t/glmakie-plot-surface-and-nonlinear-constraints/62619/8 "2023-08-31T07:16:42Z")

</div>

Awesome! Thanks for the update.

Do you mind taking a quick look at this question?  
[Colorbar with function range for a 3D contour](https://discourse.julialang.org/t/colorbar-with-function-range-for-a-3d-contour-plot-using-glmakie/103388)
