forked from plotly/plotly_matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfig2plotly.m
More file actions
79 lines (70 loc) · 2.32 KB
/
fig2plotly.m
File metadata and controls
79 lines (70 loc) · 2.32 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function [response] = fig2plotly(varargin)
% fig2plotly - plots a matlab figure object with PLOTLY
% [response] = fig2plotly()
% [response] = fig2plotly(gcf)
% [response] = fig2plotly(f)
% [response] = fig2plotly(gcf, 'property', value, ...)
% [response] = fig2plotly(f, 'property', value, ...)
% gcf - root figure object in the form of a double.
% f - root figure object in the form of a struct. Use f = get(gcf); to
% get the current figure struct.
% List of valid properties:
% 'name' - ('untitled')string, name of the plot
% 'strip' - (false)boolean, ignores all styling, uses plotly defaults
% 'open' - (true)boolean, opens a browser window with plot result
% response - a struct containing the result info of the plot
%
% For full documentation and examples, see https://plot.ly/api
%default input
f = get(gcf);
plot_name = 'untitled';
strip_style = false;
open_browser = true;
switch numel(varargin)
case 0
case 1
if isa(varargin{1}, 'double')
f = get(varargin{1});
end
if isa(varargin{1}, 'struct')
f = varargin{1};
end
otherwise
if isa(varargin{1}, 'double')
f = get(varargin{1});
end
if isa(varargin{1}, 'struct')
f = varargin{1};
end
if mod(numel(varargin),2)~=1
error('Invalid number of arguments')
else
for i=2:2:numel(varargin)
if strcmp('strip', varargin{i})
strip_style = varargin{i+1};
end
if strcmp('name', varargin{i})
plot_name = varargin{i+1};
end
if strcmp('open', varargin{i})
open_browser = varargin{i+1};
end
end
end
end
%convert figure into data and layout data structures
[data, layout, title] = convertFigure(f, strip_style);
if numel(title)>0 && strcmp('untitled', plot_name)
plot_name = title;
end
% send graph request
response = plotly(data, struct('layout', layout, ...
'filename',plot_name, ...
'fileopt', 'overwrite'));
if open_browser
status = dos(['open ' response.url ' > nul 2> nul']);
if status==1
status = dos(['start ' response.url ' > nul 2> nul']);
end
end
end