# Surface plot issues

**URL:** <https://discourse.julialang.org/t/surface-plot-issues/35603>\
**Category:** New to Julia\
**Tags:** question, plotting, plots\
**Created:** [March 5, 2020, 7:24pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603 "2020-03-05T19:24:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andre\_Mello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andre_mello/32/7333_2.png) [@Andre\_Mello](https://discourse.julialang.org/u/Andre_Mello)\
**Post date:** [March 5, 2020, 7:24pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/1 "2020-03-05T19:24:57Z")

</div>

I’m running into multiple small issues on this kind of surface plot.

1. First I’d like to know if I can make it a bit transparent. `alpha` seems to only affect the colorbar.
2. I’d like to do 1) so that I can have a wireframe on top of the surface. However, calling `wireframe!` seems to simply override the surface plot altogether.
3. Then, there’s this issue with overlapping tick numbers (1.50 from the x axis overlapping with 0.50 from the y axis), which I’m not sure how to fix.

Any help will be deeply appreciated!

![surf](https://global.discourse-cdn.com/julialang/original/2X/c/c6d74f929f37de4ce3f01bc7bb37f7a7842acb0a.png)

```julia
using Plots
x = 0.5:0.01:1.50
y = 0.5:0.01:1.50
f(x,y) = abs2(x-y)
p = plot(x,y,f,st=:surface)

```

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 5, 2020, 8:55pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/2 "2020-03-05T20:55:06Z")

</div>

I can’t really help you much other than to agree that the docs need some improvement on this front. `st=:wireframe` can give you a wirefame. I think `alpha` doesn’t work for 3D plots. A small rotation would probably fix the overlapping tick labels, but I can’t remember how to rotate the plot…

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [March 5, 2020, 10:36pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/3 "2020-03-05T22:36:49Z")

</div>

Try any of `fillalpha, surfacealpha`

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [March 5, 2020, 11:57pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/4 "2020-03-05T23:57:40Z")

</div>

You can produce a wireframe in [Gaston](https://github.com/mbaz/Gaston.jl) as follows:

```julia
using Gaston
x = 0.5:0.01:1.50
y = 0.5:0.01:1.50
f(x,y) = abs2(x-y)
surf(x,y,f,plotstyle="pm3d") # plot the surface
x2 = 0.5:0.1:1.5
y2 = 0.5:0.1:1.5
surf!(x2,y2,f) # superimpose the wireframe (default plotstyle)

```

which produces:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/5/751ce03a6f6bd93d106e8c560e2b10f8248c5836.png)

The image can be made transparent by setting the fill style “by hand”, since Gaston does not support specifying a fillstyle with `surf` yet (see page 172 in gnuplot’s manual):

`surf(x,y,f,plotstyle="pm3d",gpcom="set style fill transparent solid 0.25")`

gives you

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

---

<div class="post-metadata">

**Author:** ![Andre\_Mello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andre_mello/32/7333_2.png) [@Andre\_Mello](https://discourse.julialang.org/u/Andre_Mello)\
**Post date:** [March 11, 2020, 7:10pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/5 "2020-03-11T19:10:53Z")

</div>

> [@tbeason](#):
>
> `st=:wireframe` can give you a wirefame

The thing is `st=:wireframe`, as I’ve mentioned, just gives me this:

![fig](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6150c428d33f30fbb8e881753cfaf4353dca6c7.png)

```julia
using Plots
x = 0.5:0.01:1.50
y = 0.5:0.01:1.50
f(x,y) = abs2(x-y)
p = plot(x,y,f,st=:surface)
plot!(p,x,y,f,st=:wireframe)

```

> [@tbeason](#):
>
> A small rotation would probably fix the overlapping tick labels (…)

And unfortunately no amount of rotation on the plot fixes the tick labels.  
Rotating the labels themselves, on the other hand, sort of fixes it. Even if it still looks a bit cluttered, at least they’re not overlapping. Thanks for the tip!

![fig2](https://global.discourse-cdn.com/julialang/original/3X/0/d/0d04fbbfd012ab19f343dd10f98c570118021939.png)

```julia
(...)
p = plot(x,y,f,st=:surface)
plot!(p,xrotation=45,yrotation=45)

```

---

<div class="post-metadata">

**Author:** ![Andre\_Mello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andre_mello/32/7333_2.png) [@Andre\_Mello](https://discourse.julialang.org/u/Andre_Mello)\
**Post date:** [March 11, 2020, 7:16pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/6 "2020-03-11T19:16:11Z")

</div>

> [@baggepinnen](#):
>
> Try any of `fillalpha, surfacealpha`

`fillalpha`, just like `alpha`, only affects the colorbar.

![fig3](https://global.discourse-cdn.com/julialang/original/3X/4/a/4aa5bb0cf3c930687121facca571890a471c5a96.png)

```julia
using Plots
x = 0.5:0.01:1.50
y = 0.5:0.01:1.50
f(x,y) = abs2(x-y)
p = plot(x,y,f,st=:surface,fillalpha=0.3)
plot!(p,xrotation=45,yrotation=45)

```

As for `surfacealpha`: `Unknown key: surfacealpha`.

---

<div class="post-metadata">

**Author:** ![Andre\_Mello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andre_mello/32/7333_2.png) [@Andre\_Mello](https://discourse.julialang.org/u/Andre_Mello)\
**Post date:** [March 11, 2020, 7:22pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/7 "2020-03-11T19:22:14Z")

</div>

This is actually pretty close to what I needed! Thanks for the heads up on this package and for the detailed MWE.

However, this is for a bigger project I’m working on, which already uses `Plots.jl` basically everywhere. Switching backends just for this use case is a no go. Otherwise I’d have to change it everywhere else and I’m not sure that would be the best route.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 11, 2020, 7:35pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/8 "2020-03-11T19:35:29Z")

</div>

You should be able to do something similar without going to `Gaston`. Just superimpose two plots on each other: one with color and the other with the wireframe.

---

<div class="post-metadata">

**Author:** ![Andre\_Mello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andre_mello/32/7333_2.png) [@Andre\_Mello](https://discourse.julialang.org/u/Andre_Mello)\
**Post date:** [March 11, 2020, 7:40pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/9 "2020-03-11T19:40:12Z")

</div>

I thought I did exactly that in my response to you.

> [@Andre\_Mello](#):
>
> ```julia
> using Plots 
> x = 0.5:0.01:1.50 
> y = 0.5:0.01:1.50 
> f(x,y) = abs2(x-y) 
> p = plot(x,y,f,st=:surface) 
> plot!(p,x,y,f,st=:wireframe)
> 
> ```

Am I missing something?

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 11, 2020, 8:43pm UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/10 "2020-03-11T20:43:48Z")

</div>

Ah ok I overlooked that. Very interesting that it basically doesn’t work. I’m afraid I can’t be much more help.

---

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [March 12, 2020, 1:27am UTC](https://discourse.julialang.org/t/surface-plot-issues/35603/11 "2020-03-12T01:27:47Z")

</div>

I find 3D plotting to be an…adventure…in Plots.jl. Try different backends. Usually I find `pyplot()` to be the most robust, but this time `plotlyjs()` was the winner. However, its wireframe rendition is unusual.

```julia
surface(x,y,f,fillalpha=0.7)
wireframe!(x,y,f)

```

![temp](https://global.discourse-cdn.com/julialang/original/3X/5/1/51a2ee7766c9ce0fe303f2f2a97c444db08933d9.png)
