-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathsaveplotlyfig.m
More file actions
63 lines (50 loc) · 2.01 KB
/
saveplotlyfig.m
File metadata and controls
63 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function p = saveplotlyfig(figure_or_data, filename, varargin)
%-----------------------------SAVEPLOTLYFIG---------------------------%
% Save a MATLAB figure as a static image using Plotly
% [CALL]:
% p = saveplotlyfig(figure, filename)
% p = saveplotlyfig(data, filename)
% p = saveplotlyfig(figure, filename, varargin)
% p = saveplotlyfig(data, filename, varargin)
% [INPUTS]: [TYPE]{default} - description/'options'
% figure: [structure array]{} - structure with 'data' and 'layout' fields
% or
% figure: [plotlyfig object]{} - plotlyfig object with data and layout properties
% or
% figure: [figure handle]{} - figure handle
% data: [cell array]{} - cell array of Plotly traces
% varargin: [string]{.png} - image extension ('png','jpeg','pdf','svg')
% [OUTPUT]:
% static image save to the directory specified within the filename with the
% extension specified within filename or varargin.
% [EXAMPLE]:
% data.type = 'scatter';
% data.x = 1:10;
% data.y = 1:10;
% saveplotlyfig(data,'myimage.jpeg');
% [ADDITIONAL RESOURCES]:
% For full documentation and examples, see
% https://plot.ly/matlab/static-image-export/
%--PARSE FIGURE_OR_DATA--%
if iscell(figure_or_data)
p = plotlyfig('Visible','off');
p.data = figure_or_data;
p.layout = struct();
p.PlotOptions.Strip = false;
elseif isstruct(figure_or_data);
p = plotlyfig('Visible','off');
p.data = figure_or_data.data;
p.layout = figure_or_data.layout;
p.PlotOptions.Strip = false;
elseif isa(figure_or_data, 'plotlyfig')
p = figure_or_data;
p.PlotOptions.Strip = false;
elseif ishandle(figure_or_data) && isa(figure_or_data,"matlab.ui.Figure")
p = plotlyfig(figure_or_data, 'strip', false);
else
errkey = 'plotlySaveImage:invalidInputs';
error(errkey,plotlymsg(errkey));
end
%--MAKE CALL TO SAVEAS METHOD--%
p.saveas(filename, varargin{:});
end