User Tools

Site Tools


plotgallery3d


snippet.juliaeval
[download only julia statements]
pkgchk( "julia" => v"1.0.2", "Plots" => v"0.21.0" )

3-D Plot Gallery

Making Grids and Interpolating Data

Julia Plots.jl can always easily plot functions. It takes an x-vector and a y-vector, and a function operating on them.

snippet.juliarepl
x= [1.0:0.1:5;]; y= [4.0:0.1:9.0;]; f(x,y)= sin(x)*cos(y);

Plotting data (i.e., not mathematical functions) can be more difficult. Some functions (like the “surface” plot) know how to work with data, but other functions (like the “contour” plot) do not. Note also that different z values mean intrinsically different things in the two cases. With a function, Plots samples length(x)*length(y) points. With data, length(x)==length(y)==length(z).

snippet.juliarepl
n=100; xr= 10*rand(n); yr= 10*rand(n); zr= Float64[ sin(xr[i])+cos(yr[i]) for i=1:n];

This chapter focuses on Plots.jl, but if the need arises, there are other graphics solutions that do allow contour-plotting data, such as GMT. It should be x,y,z=GMT.peaks(); contour([x[:] y[:] z[:]], cont=1, annot=2, frame="a", fmt="png", show=1).

Surface 3-D Plot With Data

snippet.juliaeval
[download only julia statements]
using Plots
n=100; xr= 10*rand(n); yr= 10*rand(n); zr= Float64[ sin(xr[i])+cos(yr[i]) for i=1:n];
surface( xr, yr, zr, size=[800,480] )
savefig( "plotting/surfaceiplot.png" )

  • The color bar on the right is the legend. Thus, it can be turned off with legend=false.

FIXME How do I work

  • plot( x, Y, clims=);savefig( “plotting/ clims.png” ); ## the color bar limit
  • plot( x, Y, colorpalette=);savefig( “plotting/ colorpalette.png” );
  • plot( x, Y, colorbar=);savefig( “plotting/ colorbar.png” );
  • plot( x, Y, colorbartitle=);savefig( “plotting/ colorbartitle.png” );

Function-Based 3-D Plots

Plain Plot

snippet.juliaeval
[download only julia statements]
using Plots
n=50;
xr= range(1, stop=100, length=n) + rand(n)/10.0;
yr= range(100, stop=200, length=n) + rand(n)/10.0;
zr= Float64[ sin(xr[i])+cos(yr[i]) for i=1:n];
 
ptl= plot(xr, yr, zr, camera=(10,45), title="camera 10 45", legend=false, size=[800,500]);
scatter!(ptl, xr, yr, zr, c=gray(1:n))
 
ptr= plot( deepcopy(pl), camera=(90,45), title="camera 90 45", legend=false );
scatter!(ptr, xr, yr, zr)
 
pbl= plot(xr, yr, zr, camera=(45,45), title="camera 45 45", legend=false );
scatter!(pbl, xr, yr, zr)
 
pbr= plot( deepcopy(pl), camera=(90,90), title="camera 90 90", legend=false );
scatter!(pbr, xr, yr, zr)
 
plot( ptl, ptr, pbl, pbr, layout=4 )
savefig("plotting/surface-angle.png")

Surface Plot

snippet.juliaeval
[download only julia statements]
using Plots
x= [1.0:0.1:5;]; y= [4.0:0.1:9.0;]; f(x,y)= sin(x)*cos(y);
p1= surface( x, y, f,      camera=(30,30), legend=false, title="camera 30 30 (default)", size=[800,500] );	# 30 azimuth, 30 elevation is the default
p2= surface( deepcopy(p1), camera=(30,80), legend=false, title="camera 30 80" );	## note the deepcopy!
p3= surface( deepcopy(p1), camera=(80,30), legend=false, title="camera 80 30" );
p4= surface( deepcopy(p1), camera=(80,80), legend=false, title="camera 80 80" );
plot( p1, p2, p3, p4 , layout=4  )
savefig( "plotting/surface-cameras.png" );

Wireframe Plot

snippet.juliaeval
[download only julia statements]
using Plots
x= [1.0:0.1:5;]; y= [4.0:0.1:9.0;]; f(x,y)= sin(x)*cos(y);
pl= plot(x, y, f, title="camera 30 30 (default)", legend=false, seriestype=:wireframe, size=[800,500]);
pr= plot( deepcopy(pl), camera=(80,60), title="camera 80 60", legend=false, seriestype=:wireframe);
plot( pl, pr, layout=2 )
savefig("plotting/wireframe-angle.png")

Contour Plot

Contour needs a function as the third argument. It does not work with a set of points!

Regular Grid

Contour With Parameters

snippet.juliaeval
[download only julia statements]
using Plots
x= [1:5;]; y= [3:9;]; f(x,y)= x^2*sqrt(y);
contour( x, y, f, nlevels=100, width=2, size=[800,480] )
savefig("plotting/contour.png")

Irregular Grid

Contour plots can work with irregular grids, but the values have to be sorted.

snippet.juliaeval
[download only julia statements]
using Plots
f(x,y)= (3x + y^2) * abs(sin(x) + cos(y))
x= sort( rand(100)*20 )
y= sort( rand(100)*10 )
contour(x,y,f, size=[800,480])
savefig("plotting/contour-surface-irreg.png")

Colored Contour Plot (Contourf)

snippet.juliaeval
[download only julia statements]
using Plots
x= [1:10;]; y= [0:9;]; f(x,y)= x^2*sqrt(y);
contourf( x, y, f, size=[800,480] )
savefig("plotting/contourf.png")

Quiver (4-D Gradient) Plot

snippet.juliaeval
[download only julia statements]
using Plots
u= collect(1:10);
v=collect(1 : 0.1 : 1.9);
quiver(81:90, 21:30, gradient=( 1:10, 5:-1:-4), legend=false)	## x and y, then draw gradient
scatter!(81:90, 21:30)	## show the start of each arrow
savefig("plotting/quiver.png")

Heat Plot

snippet.juliaeval
[download only julia statements]
using Plots
xh= [8:32;]; yh= [2:32;]; f(x,y)= x*10+y;
annotations= [ (xh[i],yh[j],text(trunc(f(xh[i],yh[j])),7)) for i=1:length(xh) for j=1:length(yh)];  ## 5-point font
heatmap( xh, yh, f, size=[800,480], annotations=annotations, legend=false )  ## legend=false removes the sidebar
savefig("plotting/heatmap.png")

Rosenbrock Surface Plot

snippet.juliaeval
[download only julia statements]
using Plots
rosenbrock(x::Vector{<:Real})::Float64= (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2;
x= -1.5:0.1:1.5; y= -1.5:0.1:1.5; z= Surface((x,y)->rosenbrock([x,y]), x, y);
surface(x,y,z, linealpha=0.3, size=(600,600), fc=:heat)
savefig("plotting/rosenhat.png")

Spiral Plot

snippet.juliaeval
[download only julia statements]
using Plots
tvec= 0:0.1:4*pi;
plot(tvec, sin.(tvec), cos.(tvec), legend=false)   ## legend here would just be "y1"
savefig("plotting/spiral.png")

Circler Plot

snippet.juliaeval
[download only julia statements]
using Plots
N = 200; d = 8*pi/N; x= [d*n*cos.(d*n) for n in 0:N]; y= [d*n*sin.(d*n) for n in 0:N]; z= 0.0:N;
plot( x, y, z, marker=:circle, legend=false)       ## legend here would just be "y1"
savefig("plotting/circler.png")

Cool Spikes

snippet.juliaeval
[download only julia statements]
using Plots
f(x,y)= (3x + y^2) * abs(sin(x) + cos(y))
x= 0:0.1:20
y= 0:0.1:10
z= [f(i,j) for i in x, j in y]
plot(x,y,z, st=:surface)
savefig("plotting/contour-surface.png")

Backmatter

FIXME Please suggest graphs that should be added, ideally with code.

3-D plot on top, contour plot on bottom floor (and/or side walls)

Unknown and/or Unillustrated Parameters

plot( x, Y, z=); savefig( “plotting/ z.png” );

plot( x, Y, linez=); savefig( “plotting/ linez.png” );

plot( x, Y, markerz=); savefig( “plotting/ markerz.png” );

plot( x, Y, contourlabels=); savefig( “plotting/ contourlabels.png” );

plot( x, Y, contours=); savefig( “plotting/ contours.png” );

plot( x, Y, fillz=); savefig( “plotting/ fillz.png” );

plot( x, Y, levels=); savefig( “plotting/ levels.png” ); does this work for surface plot, too?

plot( x, Y, matchdimensions=); savefig( “plotting/ matchdimensions.png” ); #TEXT ## Heatmap

also, many seriestypes, such as path3d, scatter3d, contour3d, wireframe, volume, etc.

cite http://www.cas.cmc.osaka-u.ac.jp/~paoon/misc/julia/post/trouble-plots-package/

plot( x, Y, projection=polar);savefig( “plotting/projectionpolar.png” ); # default = none ; also 3d

Commonly Useful Packages on Julia Repository

Notes

References


WARNING Do not edit this page. It is autogenerated from plotgallery3d.jl with mkplotgallerytxt.pl. The plots themselves are generated by running the julia files themselves.

plotgallery3d.txt · Last modified: 2018/11/22 20:48 (external edit)