Plotting a 3D Surface

A suggestion: when you insert code, it looks much better if you use mark-up. In-line code is typeset by enclosing it with single back-tic. Displayed code should be enclosed in triple back-tics, and the first triple back-tic allows to specify the language in case you want syntax high-lighting.

The following code uses Plots and pyplot as back-end:

using Plots; pyplot();

xc = [0,0,1,1]
yc = [0,1,1,0]
zc = [1,1,2,2];

plot(xc,yc,zc,st=:surface,camera=(-30,30))

The result is as follows:

A few comments:

  1. In your first case, you use raw PyPlot. An alternative is to use pyplot as a back-end to the Plots API – as I’ve done.
  2. In your case of using Plots, you use the plotlyjs back-end. I used the pyplot back-end. There is also a gr back-end, etc. The gr back-end is the default for Plots. In my view, gr gives the purest/prettiest lines, etc. However, pyplot seems to have slightly better support of the Plots API, and also has the best \LaTeX support.
  3. Your plot using plotlyjs back-end doesn’t really show any plot in my browser. I don’t know why; in any way, I use pyplot as back-end to Plots.
  4. You import Plots using statement import Plots. That is fine; if you do so, you need to use the package name when issuing the command, i.e., Plots.plot. I import Plots by statement using Plots – the advantage is that then you don’t need to specify the package name. Such import is less “dangerous” in Julia than in, say, Python, because of Julia’s multiple dispatch idea.
  5. Observe that I used the camera option in plot – sometimes it is necessary to do this to rotate the coordinate system to get a good view of the object.
  6. Finally, I prefer to use comma (“,”) to separate vector elements; you have used semicolon (“;”). This is not a big thing here.
4 Likes