Fork on GitHub

Plotly Matlab API

< Back to Main API Page

Installation

Download and Uncompress

Click here to download MATLAB API 
(it may take a second).

Add the Plotly folder and subfolders to your MATLAB path

Find the path of the uncompressed folder (e.g. "/Users/chris/plotly"). Inside your MATLAB console, enter, e.g.

>>> api_path = "/Users/chris/plotly";
>>> addpath(genpath(api_path)) % genpath finds all subfolders

Quickstart

Begin by importing the Plotly MATLAB library

>> api_path = '/Users/chris/plotly';
>> addpath(genpath(api_path)) % genpath finds all subfolders

Sign in to your Plotly API account

>> signin(username_or_email, api_key)

Now you can make a simple API call using plotly(), and create your first graph!

>> plotly([0,1,2,3],[0,5,3,2])

Here is the response you'll receive:
(Copy and Paste the URL into your browser to see your graph!)

ans =
url: 'https://plot.ly/~username/888'
message: [1x0 char]
warning: [1x0 char]
filename: 'plot from API'
error: [1x0 char]

Initialization

To get started, sign in from your MATLAB script or the command line.

>> signin(username_or_email, api_key)

You will interact with your plotly graphs through 3 methods:

plotly plotlystyle plotlylayout

Authentication

New User - Sign Up

You can sign up on with Plotly's online GUI or through the API:

>> username="anna.lyst"
>> email="anna.lyst@plot.ly"
>> response = signup(username, email)
>> tmp_pw = response.tmp_pw
>> api_key = response.api_key

Existing User - Generate API Key

Existing users display or reset their API key here. You will be prompted to log-in if you aren't already.

Display Key
Reset Key

Your key will display here.

Documentation Examples

The following are some examples of how to use the Plotly API. You can copy and paste the code from the examples and test it out! If you're signed in, your Username and API Key will pre-populate. If not, you can still try it out with the demo account!

Search for an example, or explore the links below!

Chart Types

Line and Scatter

Area Plots

Bar Charts

Error Bars

Box Plots

Histograms

Bubble Charts

Heatmaps

Text Charts

Mixed Types

Time Series

Multiple Axes, Insets and Subplots

Multiple Axes

Subplots

Insets

Layout

File Settings

Basic Line Plot

signin('MATLABAPI', 'jzt0hr6tzv')

x0 = [1,2,3,4]; y0 = [10,15,13,17];
x1 = [2,3,4,5]; y1 = [16,5,11,9];
response = plotly(x0, y0, x1, y1)
url = response.url
filename = response.filename
Basic Line Plot

Line with Scatter

signin('MATLABAPI', 'jzt0hr6tzv')

trace0 = struct('x', [1,2,3,4], ...
  'y', [10,15,13,17], ...
  'type', 'scatter', ...
  'mode', 'markers');

trace1 = struct('x', [2,3,4,5], ...
  'y', [16,5,11,9], ...
  'type', 'scatter', ...
  'mode', 'lines');

trace2 = struct('x', [1,2,3,4], ...
  'y', [12,9,15,12], ...
  'type', 'scatter', ...
  'mode', 'lines+markers');

response = plotly({trace0, trace1, trace2});
url = response.url
filename = response.filename
Line with Scatter

Styling Line and Scatter

signin('MATLABAPI', 'jzt0hr6tzv')

%% generate some data
x1 = [1, 2, 3]; y1 = [2, 10, 12];
x2 = [1, 2, 3]; y2 = [4, 5, 6];

% specify the style of each trace
data1 = struct(...note
  'x', x1, ...
  'y', y1, ...
  'type', 'scatter', ...options
  'name', 'Experiment', ...
  'line', struct('color','rgb(3,78,123)',... options
        'width',6, ...
    'dash','dot'), ...options
  'marker', struct('opacity', 1.0, ...
    'symbol','square', ...  options
    'size',12, ...
    'color', 'rgb(54,144,192)', ...
    'line', struct('width',3, ... note
      'color','lightblue') ...
    ) ...
  );

data2 = struct( ...
  'x', x2, ...
  'y', y2, ...
  'name', 'Control', ...
  'line', struct('color', 'purple', ...
    'width', 4, ...
    'dash', 'dashdot'), ...
  'marker', struct('opacity', 0.9, ...
    'symbol', 'cross', ...
    'size', 16, ...
    'color', 'fuchsia', ...
    'line', struct( 'width', 0, ...
      'color','') ...
    ) ...
  );

response = plotly({data1, data2})
url = response.url
filename = response.filename

Styling Line and Scatter

Basic Area Plot

signin('MATLABAPI', 'jzt0hr6tzv')

trace0 = struct('x', [1,2,3,4], ...
  'y', [0,2,3,5], ...
  'fill', 'tozeroy'); options

trace1 = struct('x', [1,2,3,4], ...
  'y', [3,5,1,7], ...
  'fill', 'tonexty');

response = plotly({trace0, trace1});
url = response.url
filename = response.filename

Basic Area Plot

Basic Bar Chart

signin('MATLABAPI', 'jzt0hr6tzv')

% x can be an array of numbers or a cell array of chars
x = { {'giraffes', 'orangutans', 'monkeys'} }; note
y = [20, 14, 23];

data = struct('x', x, 'y', y, ...
  'type', 'bar');options
response = plotly({data});
url = response.url

Basic Bar Chart

Grouped Bar Chart

signin('MATLABAPI', 'jzt0hr6tzv')

categories = { {'giraffes', 'orangutans', 'monkeys'} };  note
SF = struct('name', 'SF Zoo', ...
  'x', categories, ...
  'y', [20, 14, 23], ...
  'type', 'bar');
LA = struct('name', 'LA Zoo', ...
  'x', categories, ...
  'y', [12,18,29], ...
  'type', 'bar');
layout = struct(...
  'barmode', 'group', ...
  'xaxis', struct('type', 'category'), ...
  'categories', categories);
response = plotly({LA, SF}, struct('layout',layout))
url = response.url
filename = response.filename% options

Grouped Bar Chart

Stacked Bar Chart

signin('MATLABAPI', 'jzt0hr6tzv')

[...]	% ... SF and LA data from above
layout = struct('barmode', 'stack',...%   options

	'xaxis', struct('type', 'category'),...
	'categories', categories)
response = plotly({SF, LA}, struct('layout',layout))

url = response.url
filename = response.filename

Stacked Bar Chart

Styling Bar Charts

signin('MATLABAPI', 'jzt0hr6tzv')

categories={ {'giraffes', 'orangutans', 'monkeys'} }; %note
SF = struct('name', 'SF Zoo', ...
  'x', categories, ...
  'y', [20, 14, 23], ...
  'type', 'bar', ...
  'marker', struct(... %note
    'color', 'orange',... %options
    'line', struct('color', 'grey',... %note
      'width', 3)));

LA = struct('name', 'LA Zoo', ...
  'x', categories, ...
  'y', [12,18,29], ...
  'type', 'bar', ...
  'marker', struct('color', 'rgb(111, 168, 220)', ...
    'line', struct('color', 'grey', ...
      'width', 3)));

layout = struct(...
  'title', 'Animal Population', ...
  'barmode', 'group', ... %options
  'yaxis', struct('name', '# of animals (thousands)'), ...
  'xaxis', struct('type', 'category'), ...
  'categories', categories, ...
  'bargap', 0.25, ... %note
  'bargroupgap', 0.3, ... %note
  'bardir', 'v') %options

response = plotly({LA, SF}, struct('layout',layout))
url = response.url
filename = response.filename

Styling Bar Charts

Basic Error Bars

signin('MATLABAPI', 'jzt0hr6tzv')

data = struct('x', [0, 1, 2], ...
  'y', [6, 10, 2], ...
  'error_y', struct('type', 'data', ... options
    'array', [1,2,3], ...
    'visible', true));
response = plotly({data});
url = response.url
filename = response.filename

Basic Error Bars

Percentage, Constant or Square Root

signin('MATLABAPI', 'jzt0hr6tzv')

data = struct('x', [0, 1, 2], ...
  'y', [6, 8, 4], ...
  'error_y', struct('type', 'percent', ... options
    'value', 50, ... note
    'visible', true));
response = plotly({data});
url = response.url
filename = response.filename

Percentage, Constant or Square Root

Bar Chart with Error Bars

signin('MATLABAPI', 'jzt0hr6tzv')

categories = { {'Trial 1', 'Trial 2', 'Trial 3'} };note
control = struct('x', categories, ...
  'y', [3, 6, 4], ...
  'error_y', struct('type', 'data', ... options
 	'array', [1, 0.5, 1.5], ... note
	'visible', true), ...
  'name', 'Control', ...
  'type', 'bar');

exp = struct('x', categories, ...
  'y', [4, 7, 3], ...
  'error_y', struct('type', 'data', ...
    'array', [0.5, 1, 2], ...
	'visible', true), ...
  'name', 'Experiment', ...
  'type', 'bar');

layout = struct('barmode', 'group');

response = plotly({control, exp}, struct('layout', layout));
url = response.url
filename = response.filename

Bar Chart with Error Bars

Basic Box Plot

signin('MATLABAPI', 'jzt0hr6tzv')

box1 = struct('y', [0,1,2,4], ...
	'type', 'box');
box2 = struct('y', [1,2,4,5,8], ...
	'type', 'box');
response = plotly({box1, box2});
url = response.url
filename = response.filename

Basic Box Plot

Box Plot with Jitter

signin('MATLABAPI', 'jzt0hr6tzv')

box = struct('y', randn(50,1), ...
	'type', 'box', ...
	'boxpoints', 'all', ...  options
	'jitter', 0.3, ...  	note
	'pointpos', -1.8);	 note
response = plotly({box});
url = response.url
filename = response.filename

Box Plot with Jitter

Basic Histogram

signin('MATLABAPI', 'jzt0hr6tzv')

x = randn(500, 1); % normally distributed vector
data = struct('x', x, ...
	'type', 'histogramx');
response = plotly({data});
url = response.url
filename = response.filename

Basic Histogram

Stacked Histogram

signin('MATLABAPI', 'jzt0hr6tzv')

x0 = randn(500, 1);
x1 = randn(500, 1)+1;
data0 = struct('x', x0, ...
	'type', 'histogramx');
data1 = struct('x', x1, ...
	'type', 'histogramx');
layout = struct('barmode', 'stack')	 options

response = plotly({data0, data1}, struct('layout',layout))
url = response.url
filename = response.filename

Stacked Histogram

Overlaid Histogram

signin('MATLABAPI', 'jzt0hr6tzv')

[...] % data0, data1 from the above example
layout = struct('barmode', 'overlay')  options
response = plotly({data0, data1}, struct('layout',layout))
url = response.url
filename = response.filename

Overlaid Histogram

Styling Histograms

signin('MATLABAPI', 'jzt0hr6tzv')

x0 = randn(500, 1);
x1 = randn(500, 1)+1;
data0 = struct('x', x0, ...
  'type', 'histogramx', ...
  'name', 'control', ...
  'marker',struct( ... % note
    'color', 'rgba(255, 0, 255,0.75)', ... % options
    'opacity', 0.75, ...
    'line', struct('color', 'grey', ...note
      'width', 0)), ...
  'autobinx', false, ...
  'xbins',struct( ...
    'start', -3.2, ...
    'end', 2.8, ...
    'size', 0.2), ...
  'histnorm', 'count'); % options
data1 = struct('x', x1, ...
  'name', 'experiment', ...
  'type', 'histogramx', ...
  'marker',struct( ...
    'color', 'rgba(255, 217, 102, 0.75)',...
    'opacity', 0.75), ...
  'autobinx', false, ...
  'xbins',struct( ...
    'start', -1.8, ...
    'end', 4.2, ...
    'size', 0.2));

layout = struct('barmode', 'overlay', ...% options
  'bargap', 0.25, ...% note
  'bargroupgap', 0.3, ...% note
  'bardir', 'v', ...% options
  'title', 'Sampled Results', ...
  'xaxis', struct('title', 'Value'), ...
  'yaxis', struct('title', 'Count'));
response = plotly({data0, data1}, struct('layout',layout))
url = response.url
filename = response.filename

Styling Histograms

2D Histogram

signin('MATLABAPI', 'jzt0hr6tzv')

x = randn(500, 1);
y = randn(500, 1)+1;
data = struct('x', x, 'y', y, ...
	'type', 'histogram2d')
response = plotly({data})
url = response.url
filename = response.filename

2D Histogram

2D Histogram Options

signin('MATLABAPI', 'jzt0hr6tzv')

x = randn(500, 1);
y = randn(500, 1)+1;
data = struct('x', x, 'y', y, ...
  'type', 'histogram2d', ...
  'autobinx', false, ...
  'xbins', struct( ...
    'start', -3, ...
    'end', 3, ...
    'size', 0.1), ...
  'autobiny', false, ...
  'ybins', struct( ...
    'start', -2.5, ...
    'end', 4, ...
    'size', 0.1), ...
  'zauto', false, ...
  'zmin', 0, ...
  'zmax', 0.4, ...
  'histnorm', 'probability');options
response = plotly({data})
url = response.url
filename = response.filename

2D Histogram Options

Basic Heatmap

signin('MATLABAPI', 'jzt0hr6tzv')

% z is a matrix
z = [1  20 30;
     20 1  60;
     30 60 1  ];
data = struct('z', z, ...
	    'type', 'heatmap')

% plot
response = plotly({data});
url = response.url;
filename = response.filename;

Basic Heatmap

Labelled Heatmap

signin('MATLABAPI', 'jzt0hr6tzv')

x = { {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'} };
y = { {'Morning', 'Afternoon', 'Evening'} };
z = [1. 20. 30 50 1;
     20. 1. 60 80 30;
     30. 60. 1. -10 20];
data = struct(
  'x', x, ...
  'y', y, ...
  'z', z, ...
  'type', 'heatmap')

response = plotly({data});
url = response.url;
filename = response.filename;

Labelled Heatmap

Bar Chart with Line Plot

signin('MATLABAPI', 'jzt0hr6tzv')

x0 = linspace(0, 5, 15);
y0 = sin(x0) + rand(1,15);
data0 = struct('x', x0, 'y', y0, ...
	'type', 'scatter')

x1 = [0, 1, 2, 3, 4, 5];
y1 = [1, 0.5, 0.7, -1.2, 0.3, 0.4];
data1 = struct('x', x1,'y', y1, ...
	'type', 'bar');

response = plotly({data0, data1})
url = response.url
filename = response.filename

Bar Chart with Line Plot

2D Histogram with Scatter Overlay

signin('MATLABAPI', 'jzt0hr6tzv')

x0 = randn(100,1)./5. + 0.5;
y0 = randn(100,1)./5. + 0.5;

x1 = randn(80,1)/7. + 0.1;
y1 = randn(80,1)/8. + 1.1;

x = [x0;x1];
y = [y0;y1];

data0 = struct('x', x0, ...
  'y', y0, ...
  'marker',
  	struct('symbol','circle'), ...
  'type', 'scatter', ...
  'mode', 'markers');
data1 = struct('x', x1, ...
  'y', y1,  ...
  'marker', ...
  	struct('symbol', 'cross'), ...
  'type', 'scatter', ...
  'mode', 'markers');

data_hist = struct('x', x, ...
  'y', y, ...
  'type','histogram2d')

response = plotly({data0,data1,data_hist})

2D Histogram with Scatter Overlay

Legend Visibility

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,3,6,4,5,2,3,5,4]
x2 = [0,1,2,3,4,5,6,7,8]
y2 = [0,4,7,8,3,6,3,3,4]

plotly(x,y,x2,y2);

% By default, when there are more than two traces,
% 'showlegend' is set to true.

layout = struct(...
  'showlegend', false ...
  )

response = plotlylayout(layout);
url = response.url
filename = response.filename
Legend Visibility

Legend Position Inside

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,3,6,4,5,2,3,5,4]
x2 = [0,1,2,3,4,5,6,7,8]
y2 = [0,4,7,8,3,6,3,3,4]

plotly(x,y,x2,y2);

% Position the legend inside the graph by assigning x and y values of <= 1.
% e.g :
% {'x' , 0, 'y' , 0} -- Bottom Left
% {'x' , 1, 'y' , 0} -- Bottom Right
% {'x' , 1, 'y' , 1} -- Top Right
% {'x' , 0, 'y' , 1} -- Top Left
% {'x' , .5, 'y' , 0} -- Bottom Center
% {'x' , .5, 'y' , 1} -- Top Center

legendstyle = struct('x' , 1, 'y' , 1);

% set the legend style
layout.legend = legendstyle;
response = plotlylayout(layout);
url = response.url
filename = response.filename

Legend Position Inside

Legend Position Outside

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [0,3,6,4,5,2,3,5,4];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,4,7,8,3,6,3,3,4];

plotly(x,y,x2,y2);

% Position the legend outside of the graph by assigning one of the x and y values to either 100 or -100.
% e.g :
% {'x' , 100, 'y' , 0} -- Outside Right Bottom
% {'x' , 100, 'y' , 1} -- Outside Right Top
% {'x' , 100, 'y' , .5} -- Outside Right Middle
% {'x' , 0 , 'y' , -100} -- Under Left
% {'x' , 0.5, 'y' , -100} -- Under Center
% {'x' , 1, 'y' , -100} -- Under Right

legendstyle = struct('x' , 100, 'y' , 1);

% set the legend style
layout.legend = legendstyle;
response = plotlylayout(layout);
url = response.url
filename = response.filename

Legend Position Outside

Styling the Legend

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [0,3,6,4,5,2,3,5,4];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,4,7,8,3,6,3,3,4];

plotly(x,y,x2,y2)

legendstyle = struct( ...
  'x' , 0, ...
  'y' , 1, ...
  'bgcolor' , '#E2E2E2', ... options
  'bordercolor' , '#FFFFFF', ...options
  'borderwidth' , 2, ...
  'traceorder' , 'normal', ...options
  'font' , struct( ...
    'color' , '#000', ...options
    'family' , 'sans-serif', ...options
    'size' , 12));...

% set the legend style
layout.legend = legendstyle;
response = plotlylayout(layout);
url = response.url
filename = response.filename

Styling the Legend

Legend Labels

signin('MATLABAPI', 'jzt0hr6tzv')

trace0  = struct( ...
    'x', [0,1,2,3], ...
    'y', [0,2,4,6], ...
    'name', 'Blue Trace' ...
    ), ...

trace1 = struct( ...
    'x', [0,1,2,3], ...
    'y', [8,4,2,0], ...
    'name', 'Orange Trace' ...
    ) ...

response = plotly({trace0, trace1});
url = response.url
filename = response.filename

Legend Labels

Basic Text Chart

signin('MATLABAPI', 'jzt0hr6tzv')

trace1 = struct(...
      'x', [0,1,2], 'y', [1,1,1], ...
      'name', 'Lines, Markers and Text', ...
      'text', { {'Text A', 'Text B', 'Text C'} }, ...
      'type', 'scatter', ...
      'mode', 'lines+markers+text', ...
      'textposition', 'top' ...
      );

trace2 = struct(...
      'x', [0,1,2], 'y', [2,2,2],...
      'name', 'Markers and Text',...
      'text', { {'Text D', 'Text E', 'Text F'} },...
      'type', 'scatter',...
      'mode', 'markers+text',...
      'textposition', 'bottom'...
      );
trace3 = struct(...
      'x', [0,1,2], 'y', [3,3,3],...
      'name', 'Lines and Text',...
      'text', { {'Text G', 'Text H', 'Text I'} },...
      'type', 'scatter',...
      'mode', 'lines+text',...
      'textposition' , 'bottom'...
      );

response = plotly({trace1, trace2, trace3});

%hide legend
layout = struct(...
  'showlegend',false...
)
response = plotlylayout(layout);

url = response.url
filename = response.filename
dos(['open ' response.url])

Basic Text Chart

Styling Text Charts

signin('MATLABAPI', 'jzt0hr6tzv')

trace1 = struct(...
      'x', [0,1,2], 'y', [1,1,1], ...
      'name', 'Lines, Markers and Text', ...
      'text', { {'Text A', 'Text B', 'Text C'} }, ...
      'type', 'scatter', ...
      'mode', 'lines+markers+text', ...
      'textposition', 'top', ...
      'textfont' , struct(...
        'color', '#1f77b4', ...options
        'family', 'sans serif', ...options
        'size', 18 ...
      )...
    );
trace2 = struct(...
      'x', [0,1,2], 'y', [2,2,2], ...
      'name', 'Lines and Text', ...
      'text', { {'Text G', 'Text H', 'Text I'} }, ...
      'type', 'scatter', ...
      'mode', 'lines+markers+text', ...
      'textposition' , 'bottom', ...
      'textfont' , struct(...
        'color', '#ff7f0e', ...options
        'family', 'sans serif', ...options
        'size', 18 ...
      )...
    );

response = plotly({trace1, trace2});

%hide legend
layout = struct(...
  'showlegend',false...
)
response = plotlylayout(layout);

url = response.url
filename = response.filename
dos(['open ' response.url])

Styling Text Charts

Axes Booleans

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [8,7,6,5,4,3,2,1,0];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,1,2,3,4,5,6,7,8];



axesstyle = struct( ...
      'autorange' , true, ...
      'autotick' , true, ...
      'showgrid' , false, ...
      'showline' , false, ...note
      'showticklabels' , false, ...
      'zeroline' , false, ...
      'ticks' , '' ...options
);

layout = struct( ...
      'xaxis' , axesstyle, ...
      'yaxis' , axesstyle, ...
      'showlegend' , false ...
);


response = plotly(x,y,x2,y2,struct('layout', layout));
url = response.url
filename = response.filename

Axes Booleans

Linear and Log Axes

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [8,7,6,5,4,3,2,1,0];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,1,2,3,4,5,6,7,8];


axesstyle = struct( ...
    'autorange' , true, ...
    'type' , 'log', ...options
);

layout = struct( ...
    'xaxis' , axesstyle, ...
    'yaxis' , axesstyle ...
);

response = plotly(x,y,x2,y2,struct('layout', layout));
url = response.url
filename = response.filename

Linear and Log Axes

Manual Range

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [8,7,6,5,4,3,2,1,0];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,1,2,3,4,5,6,7,8];


axesstyle = struct( ...
    'range' , [2,5] ...options
);

layout = struct( ...
    'xaxis' , axesstyle, ...
    'yaxis' , axesstyle ...
);


response = plotly(x,y,x2,y2,struct('layout', layout));
url = response.url
filename = response.filename

Manual Range

Range Mode

signin('MATLABAPI', 'jzt0hr6tzv')

x = [2,4,6];
y = [-3,0,3];


layout = struct( ...
    'showlegend' , false, ...
    'xaxis' , struct( ...
        'autorange' , true, ...
        'rangemode' , 'tozero' ...options
    ), ...
    'yaxis' , struct( ...
        'autorange' , true, ...
        'rangemode' , 'nonnegative' ...options
    ) ...
);


response = plotly(x,y,struct('layout', layout));
url = response.url
filename = response.filename

Range Mode

Axes Lines

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [8,7,6,5,4,3,2,1,0];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,1,2,3,4,5,6,7,8];


axesstyle = struct( ...
    'showline' , true, ...note
    'mirror' , 'ticks', ...optionsnote
    'linecolor' , '#636363', ...options
    'linewidth' , 6, ...
    'showgrid' , true, ...note
    'gridcolor' , '#bdbdbd', ...options
    'gridwidth' , 2, ...
    'zeroline' , true, ...note
    'zerolinecolor' , '#969696', ...options
    'zerolinewidth' , 4 ...
);

layout = struct( ...
  'xaxis' , axesstyle, ...
  'yaxis' , axesstyle ...
);


response = plotly(x,y,x2,y2,struct('layout', layout));
url = response.url
filename = response.filename

Axes Lines

Axes Ticks

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [8,7,6,5,4,3,2,1,0];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,1,2,3,4,5,6,7,8];

axesstyle = struct( ...
      'autotick' , false, ...
      'tick0' , 0, ...note
      'dtick' , .25, ...note
      'ticks' , 'outside', ...options
      'tickcolor' , '#000', ...options
      'ticklen' , 8, ...
      'tickwidth' , 4 ...
);

layout = struct( ...
  'xaxis' , axesstyle, ...
  'yaxis' , axesstyle ...
);

response = plotly(x,y,x2,y2,struct('layout', layout));
url = response.url
filename = response.filename

Axes Ticks

Axes Labels

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8];
y = [8,7,6,5,4,3,2,1,0];
x2 = [0,1,2,3,4,5,6,7,8];
y2 = [0,1,2,3,4,5,6,7,8];

axesstyle = struct( ...
      'title' , 'AXIS TITLE', ...
      'titlefont' , struct( ...
        'color' , 'lightgrey', ...options
        'family' , 'Arial, sans-serif', ...options
        'size' , 18 ...
      ), ...
      'showticklabels' , true, ...
      'tickfont' , struct( ...
        'color' , 'black', ...options
        'family' , 'Old Standard TT, serif', ...options
        'size' , 14 ...
      ), ...
      'tickangle' , 45, ...options
      'showexponent' , 'All', ...options
      'exponentformat' , 'e' ...options
);

layout = struct( ...
  'xaxis' , axesstyle, ...
  'yaxis' , axesstyle ...
);

response = plotly(x,y,x2,y2,struct('layout', layout));
url = response.url
filename = response.filename

Axes Labels

Reversed Axes

signin('MATLABAPI', 'jzt0hr6tzv')

x = [1,2] ...
y = [1,2] ...

layout = struct( ...
    'xaxis', struct( ...
      'autorange', 'reversed' ...
    ) ...
)

response = plotly(x,y,struct('layout', layout));
url = response.url
filename = response.filename

Reversed Axes

Date Axes

signin('MATLABAPI', 'jzt0hr6tzv')

%Plotly understands dates and times in format
%YYYY-MM-DD HH:MM:SS (ie, 2009-10-04 22:23:00)

x =  {'2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'};
y =  [1,3,6];

response = plotly(x,y);
url = response.url;
filename = response.filename;

Date Axes

Simple Double Axes

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
   struct( ...
    'x',[1,2,3], ...
    'y',[40,50,60], ...
      'name','yaxis data' ...
   ),
   struct( ...
      'x',[2,3,4], ...
      'y',[4,5,6], ...
      'yaxis','y2', ... % this will reference the yaxis2 object in the layout object
      'name', 'yaxis2 data' ...
   )    ...
};

layout = struct(...
   'yaxis',struct( ...
      'title', 'yaxis title'... % optional
   ), ...
   'yaxis2', struct( ...
      'title', 'yaxis2 title', ... % optional
      'titlefont',struct( ...
         'color','rgb(148, 103, 189)' ...
      ), ...
      'tickfont',struct( ...
         'color','rgb(148, 103, 189)' ...
      ), ...
      'overlaying','y', ...
      'side','right' ...
   ), ...
   'title', 'Double Y Axis Example' ...
);


response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Simple Double Axes

Simple Multiple Axes

signin('MATLABAPI', 'jzt0hr6tzv')

c = { {'#1f77b4', % muted blue
    '#ff7f0e', % safety orange
    '#2ca02c', % cooked asparagus green
    '#d62728', % brick red
    '#9467bd', % muted purple
    '#8c564b', % chestnut brown
    '#e377c2', % raspberry yogurt pink
    '#7f7f7f', % middle gray
    '#bcbd22', % curry yellow-green
    '#17becf'} }; %blue-teal

data = { ...
   struct( ...
      'x',[1,2,3], ...
      'y',[4,5,6], ...
      'name','yaxis1 data' ...
   ), ...
   struct( ...
      'x',[2,3,4], ...
      'y',[40,50,60], ...
      'name','yaxis2 data', ...
      'yaxis','y2' ... %this references the 'yaxis2' object in layout
   ), ...
   struct( ...
      'x',[3,4,5], ...
      'y',[400,500,600], ...
      'name','yaxis3 data', ...
      'yaxis','y3' ...
    ), ...
    struct( ...
    'x',[4,5,6], ...
    'y',[40000,50000,60000], ...
    'name','yaxis4 data', ...
    'yaxis','y4' ...
   ), ...
    struct( ...
    'x',[5,6,7], ...
    'y',[400000,500000,600000], ...
    'name','yaxis5 data', ...
    'yaxis','y5' ...
   ), ...
   struct( ...
    'x',[6,7,8], ...
    'y',[4000000,5000000,6000000], ...
    'name','yaxis6 data', ...
    'yaxis','y6' ...
   )...
}

layout = struct( ...
    'width',800, ...
    'xaxis', struct( ...
        'domain',[0.3,0.7] ...
    ), ...
   'yaxis',struct( ...
      'title', 'yaxis title', ...
      'titlefont', struct( ...
         'color',c{1} ...
      ), ...
      'tickfont', struct( ...
         'color',c{1} ...
      ) ...
   ), ...
   'yaxis2', struct( ...
      'overlaying','y', ...
      'side','left', ...
      'anchor','free', ...
      'position',0.15, ...
      'title', 'yaxis2 title', ...
      'titlefont', struct( ...
         'color',c{2} ...
      ), ...
      'tickfont', struct( ...
         'color',c{2} ...
      ) ...
   ), ...
   'yaxis3', struct( ...
      'overlaying','y', ...
      'side','left', ...
      'anchor','free', ...
      'position',0, ...
      'title', 'yaxis3 title', ...
      'titlefont', struct( ...
         'color',c{3} ...
      ), ...
      'tickfont', struct( ...
         'color',c{3} ...
      ) ...
   ), ...
   'yaxis4', struct( ...
      'overlaying','y', ...
      'side','right', ...
      'anchor','x', ...
      'title', 'yaxis4 title', ...
      'titlefont', struct( ...
         'color',c{4} ...
      ), ...
      'tickfont', struct( ...
         'color',c{4} ...
      ) ...
   ), ...
   'yaxis5', struct( ...
      'overlaying','y', ...
      'side','right', ...
      'anchor','free', ...
      'position',0.85, ...
      'title', 'yaxis5 title', ...
      'titlefont', struct( ...
         'color',c{5} ...
      ), ...
      'tickfont', struct( ...
         'color',c{5} ...
      ) ...
   ), ...
   'yaxis6', struct( ...
      'overlaying','y', ...
      'side','right', ...
      'anchor','free', ...
      'position',1.0, ...
      'title', 'yaxis6 title', ...
      'titlefont', struct( ...
         'color',c{6} ...
      ), ...
      'tickfont', struct( ...
         'color',c{6} ...
      ) ...
   ), ...
   'title', 'multiple y-axes example' ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Simple Multiple Axes

Simple Subplot

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
   struct( ...
    'x',[1,2,3], ...
    'y',[4,5,6] ...
   ), ...
   struct( ...
      'x',[20,30,40], ...
      'y',[50,60,70], ...
      'xaxis','x2', ...
      'yaxis','y2' ...
   ) ...
}

layout = struct( ...
    'xaxis', struct( ...
        'domain',[0,0.45] ... % i.e. let the first x-axis span the first 45% of the plot width
    ), ...
    'xaxis2', struct( ...
        'domain',[0.55,1] ... % i.e. let the second x-axis span the latter 45% of the plot width
    ), ...
    'yaxis2', struct( ...
        'anchor','x2' ... % i.e. bind the second y-axis to the start of the second x-axis
    ) ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Simple Subplot

Custom Sized Subplot

signin('MATLABAPI', 'jzt0hr6tzv')

data = {
   struct( ...
    'x',[1,2,3], ...
    'y',[4,5,6] ...
   ), ...
   struct( ...
      'x',[20,30,40], ...
      'y',[50,60,70], ...
      'xaxis','x2', ...
      'yaxis','y2' ...
   ) ...
}

layout = struct( ...
    'xaxis', struct( ...
        'domain',[0,0.7] ... % i.e. let the first x-axis span the first 70% of the plot width
    ), ...
    'xaxis2', struct( ...
        'domain',[0.8,1] ... % i.e. let the second x-axis span the latter 20% of the plot width
    ), ...
    'yaxis2', struct( ...
        'anchor','x2' ... % i.e. bind the second y-axis to the start of the second x-axis
    ) ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Custom Sized Subplot

Multiple Subplots

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
   struct( ...
    'x',[1,2,3], ...
    'y',[4,5,6] ...
   ), ...
   struct( ...
      'x',[20,30,40], ...
      'y',[50,60,70], ...
      'xaxis','x2', ...
      'yaxis','y2' ...
   ), ...
   struct( ...
      'x',[300,400,500], ...
      'y',[600,700,800], ...
      'xaxis','x3', ...
      'yaxis','y3' ...
   ), ...
   struct( ...
      'x',[4000,5000,6000], ...
      'y',[7000,8000,9000], ...
      'xaxis','x4', ...
      'yaxis','y4' ...
   ) ...
}

layout = struct( ...
    'xaxis',struct( ...
        'domain',[0,0.45] ... % let the first x-axis span the first 45% of the plot width
    ), ...
    'yaxis',struct( ...
        'domain',[0,0.45] ... % % and let the first y-axis span the first 45% of the plot height
    ), ...
    'xaxis2',struct( ...
        'domain',[0.55,1] ... % and let the second x-axis span the latter 45% of the plot width
    ), ...
    'yaxis2',struct( ...
        'domain',[0,0.45], ... % and let the second y-axis span the first 45% of the plot height
        'anchor','x2' ... % bind the horizontal position of the second y-axis to the start of the second x-axis
    ), ...
    'xaxis3',struct( ...
        'domain',[0,0.45], ...
        'anchor','y3' ... % bind the vertical position of this axis to the start of yaxis3
    ), ...
    'yaxis3',struct( ...
        'domain',[0.55,1] ...
    ), ...
    'xaxis4',struct( ...
        'domain',[0.55,1], ...
        'anchor','y4' ... % bind the vertical position of this axis to the start of yaxis4
    ), ...
    'yaxis4',struct( ...
        'domain',[0.55,1], ...
        'anchor','x4' ... % bind the horizontal position of this axis to the start of xaxis4
    ) ...
)


response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Multiple Subplots

Subplots with Shared Axes

signin('MATLABAPI', 'jzt0hr6tzv')

data = {
   struct( ...
    'x',[1,2,3], ...
    'y',[2,3,4] ...
   ), ...
   struct( ...
      'x',[20,30,40], ...
      'y',[5,5,5], ...
      'xaxis','x2', ...
      'yaxis','y' ...
   ), ...
   struct( ...
      'x',[2,3,4], ...
      'y',[600,700,800], ...
      'xaxis','x', ...
      'yaxis','y3' ...
   ), ...
   struct( ...
      'x',[4000,5000,6000], ...
      'y',[7000,8000,9000], ...
      'xaxis','x4', ...
      'yaxis','y4' ...
   ) ...
}

layout = struct( ...
    'xaxis',struct( ...
        'domain',[0,0.45] ... % let the first x-axis span the first 45% of the plot width
    ), ...
    'yaxis',struct( ...
        'domain',[0,0.45] ... % and let the first y-axis span the first 45% of the plot height
    ), ...
    'xaxis2',struct( ...
        'domain',[0.55,1] ... % and let the second x-axis span the latter 45% of the plot width
    ), ...
    'yaxis3',struct( ...
        'domain',[0.55,1] ...
    ), ...
    'xaxis4',struct( ...
        'domain',[0.55,1], ...
        'anchor','y4' ... % bind the vertical position of this axis to the start of yaxis4
    ), ...
    'yaxis4',struct( ...
        'domain',[0.55,1], ...
        'anchor','x4' ... % bind the horizontal position of this axis to the start of xaxis4
    ) ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Subplots with Shared Axes

Stacked Subplots

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
         struct('x', [0,1,2], 'y', [10,11,12]), ...
         struct('x', [2,3,4], 'y', [100,110,120], 'yaxis', 'y2', 'xaxis', 'x2'), ...
         struct('x', [3,4,5], 'y', [1000,1100,1200], 'yaxis', 'y3', 'xaxis', 'x3') ...
}

layout = struct( ...
    'yaxis', struct('domain', [0,0.8/3.]), ...
    'yaxis2', struct('domain',[0.8/3+0.1,2*0.8/3+0.1]), ...
    'yaxis3', struct('domain',[2*0.8/3+0.2,1]), ...
    'xaxis2', struct('anchor','y2'), ...
    'xaxis3', struct('anchor','y3'), ...
    'legend', struct('traceorder', 'reversed') ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Stacked Subplots

Stacked Subplots with Coupled X-Axis

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
         struct('x', [0,1,2], 'y', [10,11,12]), ...
         struct('x', [2,3,4], 'y', [100,110,120], 'yaxis', 'y2'), ...
         struct('x', [3,4,5], 'y', [1000,1100,1200], 'yaxis', 'y3') ...
}

layout=struct( ...
    'yaxis', struct('domain', [0,1./3.]), ...
    'yaxis2', struct('domain',[1./3,2./3.]), ...
    'yaxis3', struct('domain',[2./3.,1]), ...
    'legend', struct('traceorder', 'reversed') ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Stacked Subplots with Coupled X-Axis

Simple Inset

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
   struct(...
    'x',[1,2,3], ...
    'y',[4,3,2] ...
   ), ...
   struct(...
      'x',[20,30,40], ...
      'y',[30,40,50], ...
      'xaxis','x2', ...
      'yaxis','y2' ...
   ) ...
}

layout = struct(...
    'xaxis2', struct(...
        'domain', [0.6, 0.95], ...
        'anchor', 'y2' ...
    ), ...
    'yaxis2',struct(...
        'domain', [0.6, 0.95], ...
        'anchor', 'x2' ...
    ) ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Simple Inset

Plot and Margin Size

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,1,2,3,4,5,6,7,8]

layout = struct( ...
          'autosize', false, ...
          'height', 500, ...
          'width', 500, ...
          'margin', struct( ...
                    't',100, ...
                    'b',100, ...
                    'r',50, ...
                    'l',50, ...
                    'pad',4 ... % space between border and gridlines
                  ), ...
          'plot_bgcolor', '#c7c7c7', ...
          'paper_bgcolor', '#7f7f7f' ...
)

response = plotly(x,y, struct('layout',layout))
url = response.url
filename = response.filename

Plot and Margin Size

Global Font

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,1,2,3,4,5,6,7,8]
x2 = [0,1,2,3,4,5,6,7,8]
y2 = [1,0,3,2,5,4,7,6,8]

layout = struct( ...
     'title', 'Global Font', ...
     'font', struct( ...
          'color', '#7f7f7f', ...
          'family', 'Courier New, monospace', ...
          'size', 18 ...
     ) ...
)



response = plotly(x,y,x2,y2, struct('layout',layout))
url = response.url
filename = response.filename

Global Font

Titles, Axes Names and Trace Names

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,1,2,3,4,5,6,7,8]
x2 = [0,1,2,3,4,5,6,7,8]
y2 = [1,0,3,2,5,4,7,6,8]

data = { ...
     struct( ...
          'x', x, ...
          'y', y, ...
          'name','Name of Trace 1' ...
          ), ...
     struct( ...
          'x', x2, ...
          'y', y2, ...
          'name','Name of Trace 2' ...
          ) ...
}


layout = struct( ...
     'title', 'Plot Title', ...
     'xaxis', struct( ...
          'title','x Axis', ...
          'titlefont', struct( ...
               'color','#7f7f7f', ...
               'family','Courier New, monospace', ...
               'size',18 ...
          ) ...
     ), ...
     'yaxis', struct( ...
          'title','y Axis', ...
          'titlefont', struct( ...
               'color','#7f7f7f', ...
               'family','Courier New, monospace', ...
               'size',18 ...
          ) ...
     ) ...
)


response = plotly(x,y,x2,y2, struct('layout',layout))
url = response.url
filename = response.filename

Titles, Axes Names and Trace Names

Simple Annotation

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,1,3,2,4,3,4,6,5]
x2 = [0,1,2,3,4,5,6,7,8]
y2 = [0,4,5,1,2,2,3,4,2]


layout = struct( ...
    'showlegend', false, ...
    'annotations', {struct( ...
        'text', 'Annotation Text', ...
        'xref', 'x', ...
        'yref', 'y', ...
        'x', 2, ...
        'y', 5, ...
        'ax', 0, ...
        'ay', -40, ...
        'showarrow', true, ...
        'arrowhead', 7 ...
    )} ...
)

response = plotly(x,y,x2,y2, struct('layout',layout))
url = response.url
filename = response.filename

Simple Annotation

Multiple Annotations

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,1,3,2,4,3,4,6,5]
x2 = [0,1,2,3,4,5,6,7,8]
y2 = [0,4,5,1,2,2,3,4,2]


layout = struct( ...
    'showlegend', false, ...
    'annotations', {struct( ...
        'text', 'Annotation Text', ...
        'xref', 'x', ...
        'yref', 'y', ...
        'x', 2, ...
        'y', 5, ...
        'ax', 0, ...
        'ay', -40, ...
        'showarrow', true, ...
        'arrowhead', 7 ...
    ), ...
    struct( ...
        'text', 'Annotation Text 2', ...
        'xref', 'x', ...
        'yref', 'y', ...
        'x', 4, ...
        'y', 4, ...
        'ax', 0, ...
        'ay', -40, ...
        'showarrow', true, ...
        'arrowhead', 7 ...
    )} ...
)

response = plotly(x,y,x2,y2, struct('layout',layout))
url = response.url
filename = response.filename

Multiple Annotations

Styling Annotations

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,1,2,3,4,5,6,7,8]
y = [0,1,3,2,4,3,4,6,5]
x2 = [0,1,2,3,4,5,6,7,8]
y2 = [0,4,5,1,2,2,3,4,2]


layout = struct( ...
    'showlegend', false, ...
    'annotations', {struct( ...
        'text', 'max=5', ...
        'xref', 'x', ...
        'yref', 'y', ...
        'x', 2, ...
        'y', 5, ...
        'ax', 20, ...
        'ay', -30, ...
        'arrowhead', 2, ...
        'arrowsize', 1, ...
        'arrowwidth', 2, ...
        'arrowcolor', '#636363', ...
        'bgcolor', '#ff7f0e', ...
        'bordercolor', '#c7c7c7', ...
        'borderpad', 4, ...
        'borderwidth', 2, ...
        'font', struct( ...
            'color', '#ffffff', ...
            'family', 'Courier New, monospace', ...
            'size', 16 ...
        ), ...
        'opacity', 0.8, ...
        'showarrow', true, ...
        'align', 'center' ...
    )} ...
)

response = plotly(x,y,x2,y2, struct('layout',layout))
url = response.url
filename = response.filename

Styling Annotations

Simple Bubblechart

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
    struct( ...
    'x', [1,2,3,4], ...
    'y', [10,11,12,13], ...
    'marker',struct( ...
        'size', [12, 22, 32, 42], ... % diameter
        'color', { {'hsl(0,100,40)', 'hsl(33,100,40)', 'hsl(66,100,40)', 'hsl(99,100,40)'} }, ...
        'opacity',[.60, .70, .80, .90] ...
     ), ...
     'mode', 'markers' ...
     ), ...
     struct( ...
    'x', [1,2,3,4], ...
    'y', [11,12,13,14], ...
    'marker',struct( ...
        'color', 'rgb(31, 119, 180)', ...
        'size', 18, ...
        'symbol', { {'circle', 'square', 'diamond', 'cross'} } ...
     ), ...
     'mode', 'markers' ...
     ), ...
     struct( ...
    'x', [1,2,3,4], ...
    'y', [12,13,14,15], ...
    'marker',struct( ...
        'size', 18, ...
        'line',struct( ...
            'color', { {'rgb(120,120,120)', 'rgb(120,120,120)', 'red', 'rgb(120,120,120} }, ...
            'width', [2, 2, 6, 2] ...
        ) ...
    ), ...
    'mode', 'markers' ...
    ) ...
} ...

layout = struct(...
    'showlegend', false ...
)

response = plotly(data, struct('layout',layout))
url = response.url
filename = response.filename

Simple Bubblechart

Private Graph

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,2,4]
y = [0,4,2]

response = plotly(x,y, struct('world_readable',false)) %defaults to true
url = response.url
filename = response.filename

Private Graph

Public Graph

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,2,4]
y = [0,4,2]

response = plotly(x,y, struct('world_readable',true))
url = response.url
filename = response.filename

Public Graph

File Naming

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,2,4]
y = [0,4,2]

response = plotly(x,y, struct('filename','myplotlygraph'))
%or
response = plotly(x,y, struct(...
'filename','myfolder/myplotlygraph'))

url = response.url
filename = response.filename
File Naming

Data Visibility

signin('MATLABAPI', 'jzt0hr6tzv')

data = { ...
  struct( ...
    'x', [0,1,2,3], ...
    'y', [0,2,4,6], ...
    'visible', true ...
    ), ...

  struct( ...
    'x', [0,1,2,3], ...
    'y', [8,4,2,0], ...
    'visible', false ...
    ) ...
 } ...

response = plotly(data)
url = response.url
filename = response.filename

Data Visibility

New Graph

signin('MATLABAPI', 'jzt0hr6tzv')

plotly([1,2], [3,4], ...
	struct('filename','new plot', ...
	'fileopt', 'new'))

API RESPONSE:

         url: 'https://plot.ly/~demos/1053'
     message: [1x0 char]
     warning: [1x0 char]
    filename: 'new plot'
       error: [1x0 char]
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([1,2], [3,4], ...
	struct('filename','new plot', ...
	'fileopt', 'new'))
Check out the filename and url in the responses. We specified the same filename in both calls, but since we used the fileopt 'new', our second call appended '(1)' to the filename and created a new unique url for that graph. The first graph was not overwritten.

API RESPONSE:

         url: 'https://plot.ly/~demos/1054'
     message: [1x0 char]
     warning: [1x0 char]
    filename: 'new plot (1)'
       error: [1x0 char]

Overwrite

The overwrite option will save the plot with the specified filename no matter what. If a plot already exists under the same name, it will overwrite it and create a revision. If the plot with that filename doesn't exist, it will create it!
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([1,2], [3,4], ...
	struct('filename', 'same plot', ...
	'fileopt', 'overwrite'))

API RESPONSE:

         url: 'https://plot.ly/~demos/1055'
     message: [1x0 char]
     warning: [1x0 char]
    filename: 'same plot'
       error: [1x0 char]
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([10,20], [30,40], ...
	struct('filename', 'same plot', ...
	'fileopt', 'overwrite'))

API RESPONSE:

         url: 'https://plot.ly/~demos/1055'
     message: [1x0 char]
     warning: [1x0 char]
    filename: 'same plot'
       error: [1x0 char]

Append

The "append" fileopt will append the data that you supplied as new traces. If the filename doesn't exist, it will create a new file with that data.
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([1,2], [1,2], ...
	struct('filename', 'append plot', ...
	'fileopt', 'append'))
Here we're starting with one trace.
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([1,2], [3,4], ...
	struct('filename', 'append plot', ...
	'fileopt', 'append'))

Here we are appending a new trace with points (1,3) and (2,4).
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([1, 2], [4, 5], [1, 2], [5, 6], ...
	struct('filename', 'append plot', ...
	'fileopt', 'append'))
Here we are appending two new traces at points (1,4), (2,5) and (1,5), (2,6).

Extend

The "extend" fileopt will extend existing traces with your new data.
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([1,2], [1, 2], [1, 2], [2, 3], [1, 2], [3, 4], ...
	struct('filename', 'extend plot', ...
	'fileopt', 'extend'))
If there is no data in the plot, 'extend' will create new traces.
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([3,4], [2, 1], [3, 4], [3, 2], [3, 4], [4, 3], ...
	struct('filename', 'extend plot', ...
	'fileopt', 'extend'))
If there is data in the plot, the existing traces will be extended with the data in the order that it is supplied.
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([4,5], [2, 3], ...
	struct('filename', 'extend plot', ...
	'fileopt', 'extend', ...
	'traces' , [1]))
You can also choose which trace to extend with the "traces" argument. Here we extend the second trace. (traces=[1])
signin('MATLABAPI', 'jzt0hr6tzv')

plotly([5,6], [3,3], [4, 5], [1, 1], ...
	struct('filename', 'extend plot', ...
	'fileopt', 'extend', ...
	'traces' , [2,0]))
The traces option accepts an array as an argument. Here we extend the 3rd trace in the plot with the first data set that we supply, and the 1st trace in the plot with the second data set.

Setting Style

A simple example:
>> plotlystyle({struct('type','bar'), struct('type','scatter','marker',struct('symbol','square', 'color','marker'))})
This sets the first data trace to a bar chart and the second data trace to a scatter plot with purple square scatter points.

>> plotlystyle({data1,...,datan]}, kwargs)
{data1,...} is a cell array of structs
datai is a Plotly formatted data struct that customizes the style of the i'th trace. It is identical to the datai structs used in plotly(data1,...) except that it doesn't contain the keys x or y (i.e. it doesn't contain any data).

kwargs is an optional struct with the following optional keys:
kwargs.filename: filename of the plot inside your plotly account
kwargs.traces: an array that specifies which traces to style. If not specified, then traces are styled in the order of the data structs or, if supplied, applied to the trace specified by the datai.name value.

Setting Layout

A simple example:
plotlylayout({'title':'Hello World'})
This sets your plot's title to Hello World.
The general syntax is
plotlylayout(layout, kwargs)
layout is a Plotly formatted layout dictionary that customizes the style of the layout, the axes, and the legend.

kwargs represents optional arguments. Accepted arguments are:
filename: filename of the plot inside your plotly account. If not specified, then the style is applied to the last plot that was made in your API session.

File Sharing

signin('MATLABAPI', 'jzt0hr6tzv')

x = [0,2,4]
y = [0,4,2]


response = plotly(x,y, struct(...
'filename','lab_results/experiment1'))

url = response.url
filename = response.filename

When you share a folder in the Plotly tool, files created within that folder using the API are automatically shared.

In this case user demos has shared the folder lab_results with batman and robin.

When demos saves a file (experiment1 inside lab_results, batman

IFrames

Plotly makes it easy to embed your interactive graphs into your HTML as iframes.
For example, the graph below was embedded using the following code:

<iframe id="igraph" style='border:none' src="https://plot.ly/~Dreamshot/212/550/550" width="100%"></iframe>
Replace the src attribute with the url to your plotly graph. The last two values in the src attribute represent the width and height, respectively.

Wide Example


<iframe id="igraph" style='border:none' src="https://plot.ly/~Dreamshot/212/800/600" width="100%"></iframe>

Pocket Sized Example


<iframe id="igraph" style='border:none' src="https://plot.ly/~Dreamshot/212/400/400" width="100%"></iframe>

Formal Syntax

A simple example:
>> plotly([0,1],[10,11])
or in an alternate syntax
>> plotly({struct('x',[0,1],'y',[10,11]})
The general plotting syntax is
>> plotly(x1, y1,...,xn,yn, kwargs)
or
>> plotly({data1,...,datan}, kwargs)
x1, y1 are arrays with numbers or cell arrays with strings as elements.

{data1,...} is a cell array and data1 is a struct with at least the fields x and y, i.e.
datai = struct('x', x1, 'y', y1)
but can contain more fields with styling and chart-type data. For example,
data1=struct('x', [0,1],'y', [10,11],'name','Exp Results', 'type','scatter', 'marker',struct('symbol','square',
'color','purple'))
specifies a scatter trace with purple square data markers that is named Exp Results.

kwargs is an optional struct with the following optional keys:
kwargs.filename: filename of the plot inside your plotly account
kwargs.fileopt: file-options: 'new', 'overwrite', or 'append'
kwargs.layout: a Plotly formatted layout struct describing layout options.
kwargs.style: a Plotly formatted style struct describing the style of all the data traces.
kwargs.world_readable: a boolean. If true, then the graph will be public. If false, then only you can see it. Default is true.