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

Filled Area Plots in MATLAB®

How to make a filled area plot in MATLAB®. An area chart displays a solid color between the traces of a graph.


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

y = [1, 5, 3;
     3, 2, 7;
     1, 5, 3;
     2, 6, 1];
fig = figure
area(y)

%--PLOTLY--%

% Strip MATLAB<sup>&reg;</sup> style by default!
response = fig2plotly(fig, 'filename', 'matlab-basic-area');
plotly_url = response.url;
% Learn about API authentication here: https://plotly.com/matlab/getting-started
% Find your api_key here: https://plotly.com/settings/api

trace1 = struct(...
  'x', [1, 2, 3, 4], ...
  'y', [0, 2, 3, 5], ...
  'fill', 'tozeroy', ...
  'type', 'scatter');
trace2 = struct(...
  'x', [1, 2, 3, 4], ...
  'y', [3, 5, 1, 7], ...
  'fill', 'tonexty', ...
  'type', 'scatter');
data = {trace1, trace2};
response = plotly(data, struct('filename', 'basic-area', 'fileopt', 'overwrite'));
plot_url = response.url

MATLAB is a registered trademark of The MathWorks, Inc.