# 3D plots -- possible to change view-point?

**URL:** <https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155>\
**Category:** Visualization\
**Created:** [April 4, 2018, 12:59pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155 "2018-04-04T12:59:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 4, 2018, 12:59pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/1 "2018-04-04T12:59:33Z")

</div>

I’m doing a 3D path plot – it looks ok, but I think it would be possible to get a better 3D feeling with a modified view-point (3D plot with time as parameter, starting at turquois and ending in gold…):

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

Question:

- Does Plots have keywords for controlling from where the plot is viewed?
- Is it possible to change the back-drop grey color?

-B

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [April 4, 2018, 1:24pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/2 "2018-04-04T13:24:18Z")

</div>

I think you want the `camera` keyword argument for that, see [here](http://docs.juliaplots.org/latest/#simple-is-beautiful). Background color can be set with the `background_color` keyword argument.  
Try e.g.

```julia
plot(rand(100,100), background_color = :white, st = :surface, camera = (40, 30))

```

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [April 4, 2018, 2:56pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/3 "2018-04-04T14:56:40Z")

</div>

Thanks a lot, pfitzseb! I tried with `camera=(-30,35)`, and added some projection “shadows” – don’t know whether I like the shadows or not…

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/0/50ab44f61c6f5a47fdfae609d5d8a6644ce82d62.png)

The `background_color` keyword doesn’t really do what I want: I was looking for the keyword for changing the grayish color of the planes/backdrops of the plot, i.e., the xy-plan, the yz-plane and the xz-plane. Maybe it is ok the way it is, but still useful to be able to change the color…

A couple of more observations:

- I didn’t find documentation of the `camera` keyword; it would be nice to see documented the meaning of the two numbers in the pair – I see that they are angles rotating around the z-axis and the azimuth (?), respectively. Is it possible to also set the viewing _radius_?
- When the first item in the `camera` pair is _negative_, it would perhaps be nice if the `zlabel` was flipped 180 degrees? Or is it better to do this manually? (Keyword…?)
- I’m slightly puzzled by the “heat bar” (or rather: parameter bar)… sometimes it disappears when I set `legend = false` together with the legend, and sometimes not.

-B

---

<div class="post-metadata">

**Author:** ![Sonorg\_19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sonorg_19/32/9794_2.png) [@Sonorg\_19](https://discourse.julialang.org/u/Sonorg_19)\
**Post date:** [October 25, 2019, 11:50pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/4 "2019-10-25T23:50:11Z")

</div>

Hi, How did you put the shadows?

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 26, 2019, 11:09am UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/5 "2019-10-26T11:09:05Z")

</div>

I don’t recall exactly… I should have documented it better. Give me some time, and I’ll see if I can dig up the Jupyter notebook where I did it. I did it as part of some work with a group task in my modelling course – in 2017, I think.

But _essentially_, created 3 copies of the original curves, and set in turn the value of each axis to a constant value, and plotted those curves with color grey. Looking back, I also like the change of color with the time parameter, which indicates time going from dark turquois (zero time) to gold (final time) – it gives an indication of direction of time.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 27, 2019, 12:16pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/6 "2019-10-27T12:16:44Z")

</div>

OK… here is the way I added the projected shadows. First: without shadows…

```julia
plot(CAis,CBis,Tis,lw=2,lc=cgrad([c_usn["purple_1"],c_usn["gray_50_3"],c_usn["gold_2"]]),line_z=tis,title="Seborg IS reactor",xlabel=L"$c_\mathrm{A}$ [mol/L]",ylabel=L"$c_\mathrm{B}$ [mol/L]",zlabel=L"$T$ [$^\circ$C]",legend=false)

```

leads to the plot:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/6/c60657a5c4434a6b9f936b9bfef61a265b180d82.jpeg)

Here, vectors `CAis`, `CBis`, and `Tis` are results of solving differential equations, and are available at time points given by vector `tis`. Don’t worry about the colors `c_usn["purple_1"]` and `c_usn["gray_50_3"]`) – you can use any Julia colors. I chose to create a dictionary `c_usn` with the colors of the graphic profile of my employer…

OK – to add projected shadows, I did the following:

```julia
plot(ones(size(CAis)).*0,CBis,Tis,lw=2,la=0.4,lc=c_usn["gray_25_light_3"],ls=:solid, camera=(140,20))
plot!(CAis,ones(size(CBis)).*0.,Tis,lw=2,la=0.4,lc=c_usn["gray_25_light_3"],ls=:solid)
plot!(CAis,CBis,ones(size(Tis)).*(350-273.15),lw=2,la=0.4,lc=c_usn["gray_25_light_3"],ls=:solid)
plot!(CAis,CBis,Tis,lw=2,lc=cgrad([c_usn["purple_1"],c_usn["gray_50_3"],c_usn["gold_2"]]),line_z=tis,title="Seborg IS reactor",xlabel=L"$c_\mathrm{A}$ [mol/L]",ylabel=L"$c_\mathrm{B}$ [mol/L]",zlabel=L"$T$ [$^\circ$C]",legend=false)

```

leading to:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/5/15e6bcf45212692fbf31e728216885486498c48f.jpeg)

Two comments:

1. The camera angle appears to be somewhat arbitrary. I could probably enforce it using plot keyword `camera=(x,y)` where `x` and `y` are two angles in degrees.
2. It seems to be a little arbitrary whether the color bar on the right hand side of the latter plot shows up or not.

---

<div class="post-metadata">

**Author:** ![Sonorg\_19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sonorg_19/32/9794_2.png) [@Sonorg\_19](https://discourse.julialang.org/u/Sonorg_19)\
**Post date:** [October 28, 2019, 8:48pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/7 "2019-10-28T20:48:02Z")

</div>

Thanks a lot, I will try it on my plots.

---

<div class="post-metadata">

**Author:** ![Sonorg\_19](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sonorg_19/32/9794_2.png) [@Sonorg\_19](https://discourse.julialang.org/u/Sonorg_19)\
**Post date:** [October 29, 2019, 7:52pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/9 "2019-10-29T19:52:32Z")

</div>

BLI, thanks, it worked perfectly on my plots (as a .gif). Here’s my code, hope it helps.

Coord was an array with all the points to plot.

```julia

gr(show = :ijulia) 
plot() 
framestyle=[:zerolines]
markershapes= [:circle];
anim = @animate for i in 1:N*10
    x=Coord[i,1]
    y=Coord[i,2]
    w=Coord[i,3]
    plot!((0,0,w),lw=2,la=0.4,seriestype=:scatter, color=:grey, ls=:solid, camera=(-20,20))
    plot!((x,0,0),lw=2,la=0.4,seriestype=:scatter, color=:grey, ls=:solid, camera=(-20,20))
    plot!((0,y,0),lw=2,la=0.4,seriestype=:scatter, color=:grey, ls=:solid, camera=(-20,20))
    
    plot!((x,y,w),linewidth=3,seriestype=:scatter,legend = false, xlim=(0,1),ylim=(0,1),zlim=(0,1), 
       gridstyle=:solid, gridlinewidth=2, foreground_color_grid=:grey,
        size = (500,500),bg=:white, 
      zlabel=("k_{3}"), xlabel=("k_{1}"), ylabel=("k_{2}"), camera = (-20, 20))
    

 
    end every 1;
gif(anim,"anim1.gif")

```

---

<div class="post-metadata">

**Author:** ![elsuizo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elsuizo/32/89_2.png) [@elsuizo](https://discourse.julialang.org/u/elsuizo)\
**Post date:** [January 3, 2020, 8:35pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/10 "2020-01-03T20:35:18Z")

</div>

Nice !!! what are the `lc=c_usn["gray_25_light_3"]` option??? i got an error `c_usn not defined`  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [January 3, 2020, 11:03pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/11 "2020-01-03T23:03:06Z")

</div>

Observe what I wrote:

> [@BLI](#):
>
> Don’t worry about the colors `c_usn["purple_1"]` and `c_usn["gray_50_3"]` ) – you can use any Julia colors.

So… “c\_usn”… “c” just implies colors, and “usn” is the abbreviation for my employer. I simply created a dictionary of colors from the graphical profile of my employer…

```julia
c_usn = Dict("purple_1"=>colorant"#4646A5", "teal_1"=>colorant"#3BAFA2",
    "turquoise_2"=>colorant"#27B2DO","red_2"=>colorant"#D64349",
    "gold_2"=>colorant"#FFD240",
    "teal_3"=>colorant"#7E9492","green_light_3"=>colorant"#A6B6B3",
    "aqua_3"=>colorant"#C8D7D7","gray_50_3"=>colorant"#8C9696",
    "gray_25_3"=>colorant"#AFB6B3","gray_25_light_3"=>colorant"#D2D7D7");

```

Choose some colors that make sense for you.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [January 3, 2020, 11:14pm UTC](https://discourse.julialang.org/t/3d-plots-possible-to-change-view-point/10155/12 "2020-01-03T23:14:03Z")

</div>

…and `lc = c_usn["gray_25_light_3"] ` simply sets the line color (`lc`) to the specified color (you could just as well write `lc = colorant"#D2D7D2"` or `linecolor = colorant"#D2D7D2"`).

To choose colors, see, e.g., [HTML Color Names](https://www.w3schools.com/colors/colors_names.asp). Say you want to use the color named `CornflowerBlue`… Then you either write `lc = :cornflowerblue` or `lc = colorant"#6495ED"`. I think most of the named HTML colors such as `CornflowerBlue` have been defined as symbols in Julia (e.g., `:cornflowerblue`).

In my case, someone from our communication department gave me a PowerPoint file which included the graphic profile colors. I used the color picker in PowerPoint to find the hex code for the colors, such as `#D2D7D7` where `D2` is hex code for the Red color, `D7` is the hex code for the Green color, and `D7` is the hex code for the Blue color (RGB).
