# Single-color 3D surface plot

**URL:** <https://discourse.julialang.org/t/single-color-3d-surface-plot/103166>\
**Category:** Visualization\
**Tags:** plotlyjs\
**Created:** [August 24, 2023, 7:39pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166 "2023-08-24T19:39:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [August 24, 2023, 7:39pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/1 "2023-08-24T19:39:27Z")

</div>

I’m trying to plot a 3D surface as a single, semi-transparent color. Here’s what I’ve tried:

```julia
using PlotlyJS

f(x, y) = 10 .* sin.(x./5) .+ 8 .* cos.(y./7) .+ y./30;
xs = ys = 0:1:100; 
zs = f.(xs', ys);

plot(surface(x=xs, y=ys, z=zs, color=:black, opacity=0.5))

```

 ![newplot](https://global.discourse-cdn.com/julialang/original/3X/4/4/440ee3509d001bd91fbc550496f58f3a04eba954.png)

Above, you see I’ve tried to set `color=:black`, and I’ve also tried `surfacecolor=:black`, but these requests seem to be ignored in favor of color-scaling based on z value.

How do I make a plain black surface?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 24, 2023, 10:18pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/2 "2023-08-24T22:18:00Z")

</div>

Would the `Greys` colorscale please:

`plot(surface(x=xs, y=ys, z=zs, colorscale="Greys", opacity=0.5))`

---

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [August 24, 2023, 10:21pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/3 "2023-08-24T22:21:25Z")

</div>

Thanks @rafael.guerra, but not quite. The goal is just to make the surface a single color.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [August 24, 2023, 10:50pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/4 "2023-08-24T22:50:39Z")

</div>

Close to this?

```julia
using GMT

C = makecpt(range=(-15,0), cmap=200);
imshow("ackley", view=(159,30), cmap=C, shade=true, transparency=50, figname=:xx)

```

 ![xx](https://global.discourse-cdn.com/julialang/original/3X/7/f/7f330f443050db1b036cd3f392960253a0e50aa0.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 24, 2023, 11:21pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/5 "2023-08-24T23:21:03Z")

</div>

Fwiw, this does pick a single color from the `Greys` palette:

```julia
plot(surface(x=xs, y=ys, z=zs, surfacecolor=0*zs, colorscale="Greys", opacity=0.5))

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 24, 2023, 11:31pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/6 "2023-08-24T23:31:50Z")

</div>

With `GR`(at least, maybe with other too), you can use `cgrad()` with identical initial and end colors, to achieve that:

```julia
julia> using Plots

julia> xs = ys = 0:1:100;

julia> zs = f.(xs', ys);

julia> surface(xs, ys, zs, xlabel = "longer xlabel", ylabel = "longer ylabel", zlabel = "longer zlabel", c=cgrad([:green,:green]))

```

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

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [August 25, 2023, 5:20am UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/7 "2023-08-25T05:20:45Z")

</div>

To get a single-color surface you should define a constant `colorscale=[[0, "black"], [1, "black"]]`  
or  
`colorscale=[[0, "#000000"], [1, "#000000"]]`

```julia
plot(surface(x=xs, y=ys, z=zs, 
             colorscale=[[0, "black"], [1, "black"]], 
             showscale=false,
             opacity=0.5,
             lighting=attr(ambient=0.5, 
                           diffuse=0.4,
                           fresnel=0.4,        
                           specular=0.5,
                           roughness=0.5),
             lightposition=attr(x=100,
                                y=100,
                                z=1000)
        ),
    Layout(width=600, height=400, font_size=10))

```

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [August 25, 2023, 6:43am UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/8 "2023-08-25T06:43:18Z")

</div>

In case you’re wondering what @empet 's plot looks like:

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

---

<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 25, 2023, 7:05am UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/9 "2023-08-25T07:05:42Z")

</div>

Makie’s solution looks like this:

```plaintext
using GLMakie
f(x, y) = 10 .* sin.(x./5) .+ 8 .* cos.(y./7) .+ y./30;
xs = ys = 0:1:100; 
zs = f.(xs', ys)
surface(xs, ys, zs; colormap=[(:black,0.5)], transparency=true)

```

---

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [August 25, 2023, 5:31pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/10 "2023-08-25T17:31:16Z")

</div>

Yes, this is exactly what I was looking for, and I appreciate the fancy lighting options. Thank you!

Question: Is there any hit to performance when the surface is colorscaled? I only ask because MATLAB has an easier time rendering a solid blue surface than a color-scaled blue surface. In our current solution, we’ve scaled from one color to the same color, so I’m wondering if that impacts the rendering speed.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [August 25, 2023, 6:01pm UTC](https://discourse.julialang.org/t/single-color-3d-surface-plot/103166/11 "2023-08-25T18:01:28Z")

</div>

There is no other mean to define a surface in PlotlyJS beside giving a colorscale. That’s why I don’t think that colorscale could affect the performance.
