#
3D Surface Plots
in MATLAB^{®}

How to make 3D surface plots in MATLAB^{®}.

```
[X,Y,Z] = peaks(25);
figure
surf(X,Y,Z);
fig2plotly()
```

```
%Add a grid of polar coordinates
theta = (0:5:360)*pi/180;
rho = 0:.05:1;
[TH,R] = meshgrid(theta,rho);
%Transform the polar coordinate data into
%2 dimensional Cartesian (xy) coordinates
[X,Y] = pol2cart(TH,R);
%Generate the complex matrix Z
Z = X + 1i*Y;
%Dispay a surface of the mathematical function
f = (Z.^4-1).^(1/4);
%Create figure
fig = figure;
surf(X,Y,abs(f))
colormap winter
%Send to Plotly!
response = fig2plotly(fig, 'strip', true, ...
'filename', 'PolarCoor', ...
'fileopt','overwrite');
```

```
gv = linspace(-30,30,50); % adjust for appropriate domain
[xx yy zz]=meshgrid(gv, gv, gv);
F = xx.^2 + 2*yy.^2 + 0.5*zz.^2 + .4*xx.*yy + .5*xx.*zz + .6*yy.*zz + 7*xx + 8*yy + 9*zz - 100;
fig = figure
isosurface(xx, yy, zz, F, 0)
resp = fig2plotly(fig,'strip',false)
plotly_url = resp.url
```

Inspired from Stack Overflow

```
% Learn about API authentication here: https://plotly.com/matlab/getting-started
% Find your api_key here: https://plotly.com/settings/api
f = @(x, y) real(atan(x + i*y));
ezsurf(f);
title('Function of two variables');
response = fig2plotly;
plotly_url = response.url;
```

Inspired from Matlab Docs.

```
Download kleinBottle.m from <a href="http://www.mathworks.com/matlabcentral/fileexchange/5880-klein-bottle/content//kleinBottle.m" target="_blank">MATLAB<sup>®</sup> File Exchange</a>
[x, y, z] = klein();
h = surf(x, y, z);
p = fig2plotly(h);
```

```
% Learn about API authentication here: https://plotly.com/matlab/getting-started
% Find your api_key here: https://plotly.com/settings/api
z = 0:4*pi; % <-- Or whatever range you want for z
t = 0:2*pi;
[Z,T] = meshgrid(z,t);
X = sin(Z).*cos(T);
Y = sin(Z).*sin(T);
surf(X,Y,Z)
response = fig2plotly;
plotly_url = response.url;
```

*MATLAB is a registered trademark of The MathWorks, Inc.*