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

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…):

Question:

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

-B

3 Likes

I think you want the camera keyword argument for that, see here. Background color can be set with the background_color keyword argument.
Try e.g.

plot(rand(100,100), background_color = :white, st = :surface, camera = (40, 30))
2 Likes

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…

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

5 Likes

Hi, How did you put the shadows?

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.

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

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:

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:

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:

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.
2 Likes

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

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.


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")
1 Like

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

1 Like

Observe what I wrote:

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…

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.

2 Likes

…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. 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).

2 Likes