Show Sidebar Hide Sidebar

Line and Scatter in MATLAB

How to make a Line and Scatter graphs in MATLAB.

% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

D = [0 4 8 12 16 20 24 28 32];
F = [0 .23 .36 .43 .52 .64 .78 .85 .92];  
plot(D,F,'.b')
p = polyfit(D,F,1)
f = polyval(p,D);
hold on
plot(D,f,'--r')

resp = fig2plotly;
plotly_url = resp.url;

Inspired from Matlab Forum
% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

x = linspace(0,4*pi,10);
A = 2, B = 3, C = 1;

y = A * x.^2 + B * x + C

p = polyfit(x,y,2);

k = polyval(p,x)

fig = figure;
hold on
plot(x,y,'ro')
plot(x,k,'b-')
hold off

resp = fig2plotly(fig, 'strip',false)
plotly_url = resp.url;
% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

load gas
fig = figure;
qqplot(price1,price2);
title('Quantile Quantile Plot with two distributions')

resp = fig2plotly(fig, 'strip',false)
plotly_url = resp.url
% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

x = 1:1:100; 
y = randi(100,1,100)
fig = figure;
hold on
scatter(x,y);
plot(x+2,y)
hold off

resp = fig2plotly(fig)
plotly_url = resp.url

% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

x = linspace(1,10,10)
y = randi(10,1,10)

x1 = linspace(1,2*pi, 100)

fig = figure;
hold on
plot(x,y)
plot([1 10],[5 5])
plot([-5 5],[1 10])
plot(x1, sin(x1))
plot(x1, exp(x1))
xlim([-6 10])
ylim([-10 10])
hold off;

resp = fig2plotly(fig, 'strip',false)
plotly_url = resp.url;
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.