Black Lives Matter. Please consider donating to Black Girls Code today.

3D Surface Plots in MATLAB®

How to make 3D surface plots in MATLAB®.

[X,Y,Z] = peaks(25);
%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;
colormap winter
%Send to Plotly!
response = fig2plotly(fig, 'strip', true, ...
                      'filename', 'PolarCoor', ... 
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:
% Find your api_key here:

f = @(x, y) real(atan(x + i*y));
title('Function of two variables');

response = fig2plotly;
plotly_url = response.url;
Inspired from Matlab Docs.
Download kleinBottle.m from <a href="" target="_blank">MATLAB<sup>&reg;</sup> File Exchange</a>

[x, y, z] = klein();
h = surf(x, y, z);
p = fig2plotly(h);
% Learn about API authentication here:
% Find your api_key here:

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);

response = fig2plotly;
plotly_url = response.url;

MATLAB is a registered trademark of The MathWorks, Inc.