Show Sidebar Hide Sidebar

# 3D Line Plots in MATLAB

How to make 3D line plots in MATLAB.

#### plot3

``````[X1,Y1]= meshgrid(-5:.2:5,-5:.2:5);
syms x y
f=((x^2-1)+(y^2-4)+(x^2-1)*(y^2-4))/(x^2+y^2+1)^2
zfun = @(x, y) eval(vectorize(f))
Z1=zfun(X1,Y1);
plot3(X1,Y1,Z1)
fig2plotly()
``````

#### 3d line and scatter plot

``````Example from code from NCI website

[sx sy sz] = meshgrid(80,20:1:55,5);
verts = stream3(x,y,z,u,v,w,sx,sy,sz);
sl = streamline(verts);
iverts = interpstreamspeed(x,y,z,u,v,w,verts,.025);
axis tight; view(30,30); daspect([1 1 .125])
camproj perspective; camva(8)
set(gca,'DrawMode','fast')
box on
streamparticles(iverts,35,'animate',10,'ParticleAlignment','on')
Warning: The DrawMode property will be removed in a future release. Use the SortMethod property instead.
fig2plotly()
``````

#### 3d line and scatter plot

``````Example from code from NCI website

[sx sy sz] = meshgrid(80,20:1:55,5);
verts = stream3(x,y,z,u,v,w,sx,sy,sz);
sl = streamline(verts);
iverts = interpstreamspeed(x,y,z,u,v,w,verts,.025);
axis tight; view(30,30); daspect([1 1 .125])
camproj perspective; camva(8)
set(gca,'DrawMode','fast')
box on
streamparticles(iverts,35,'animate',10,'ParticleAlignment','on')
Warning: The DrawMode property will be removed in a future release. Use the SortMethod property instead.
fig2plotly()
``````

#### Plot a 3D Box with Given Size and Thickness

``````sidelength = 3
verts = ([0 0 0;0 1 0;1 1 0;1 0 0;0 0 1;0 1 1;1 1 1;1 0 1]-0.5).*sidelength;

face = [1 2 3 4;5 6 7 8;3 4 8 7;1 2 6 5;2 3 7 6;4 1 8 5];

fig = figure;
h = patch('Faces',face,'Vertices',verts,'FaceColor','b','EdgeColor','b');

response =fig2plotly(fig, 'strip',false);
response.layout.xaxis1.range  = [-5 5]
response.layout.yaxis1.range  = [-5 5]
response.layout.zaxis1.range  = [-5 5]

response2 = plotly(response.data, response.layout, 'strip',false);
plotly_url = response2.url;``````