forked from plotly/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2015-09-09-matlab-reference.html
95 lines (76 loc) · 5.23 KB
/
2015-09-09-matlab-reference.html
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
permalink: /matlab/reference/
layout: langindex
page_type: reference
language: matlab
name: plotly chart attribute reference
title: plotly chart attribute reference
description: The extensive reference of plotly chart attributes for plotly's MATLAB library.
---
<h2><code>matlab</code> figure reference</h2>
<div class="row">
<p>
<code>fig2plotly</code> converts MATLAB figures to online Plotly graphs. MATLAB describes figures differently than Plotly. Plotly's MATLAB library crawls the MATLAB figure objects and translates the MATLAB attributes into the structure that Plotly uses to describe and draw data visualizations.<br><br>
You may wish to customize the figure <i>after</i> you have translated it but <i>before</i> you have sent it to Plotly. You can customize every attribute of a plotly graph: the hover text, the colorscales, the gridlines, the histogram binning, etc.<br><br>
<code>plotly</code> charts are described declaratively with <code>struct</code> and <code>cell array</code> objects. This page contains an extensive list of the keys used to describe plotly graphs inside these <code>struct</code> objects.
Here is a simple example of how to translate a MATLAB figure, modify some attributes, and then send it to Plotly.
<pre>>> x = linspace(-2*pi, 2*pi);
>> y1 = sin(x);
>> y2 = cos(x);
>> plot(x, y1, x, y2);
%% Translate the figure from MATLAB to Plotly
>> fig = plotlyfig(gcf);
>> fig.PlotOptions.Strip = 0; % If 0, don't strip MATLAB's styling in translation. If 1, strip MATLAB's styling.
>> fig.data
ans =
[1x1 struct] [1x1 struct]
>> fig.data{1} % The 'type' of this trace is 'scatter'. scatter's reference: <a href="#scatter">#scatter</a>
ans =
xaxis: 'x1' % more about scatter's 'xaxis': <a href="#scatter-xaxis">#scatter-xaxis</a>
yaxis: 'y1' % scatter's 'yaxis' property: <a href="#scatter-yaxis">#scatter-yaxis</a>
type: 'scatter'
visible: 1 % scatter's 'visible' property: <a href="#scatter-visible">#scatter-visible</a>
x: [1x100 double] % scatter's 'x' property: <a href="#scatter-x">#scatter-x</a>
y: [1x100 double] % scatter's 'y' property: <a href="#scatter-y">#scatter-y</a>
name: '' % scatter's 'name' property: <a href="#scatter-y">#scatter-name</a>
mode: 'lines' % scatter's 'mode' property: <a href="#scatter-y">#scatter-mode</a>
line: [1x1 struct] % scatter's 'line' property: <a href="#scatter-y">#scatter-line</a>
marker: [1x1 struct] % scatter's 'marker' property: <a href="#scatter-y">#scatter-marker</a>
showlegend: 1 % scatter's 'showlegend': <a href="#scatter-y">#scatter-marker</a>
%% Modify or add new properties to this trace
>> fig.data{1}.name = 'Current'; % Update the legend name to 'Current'
>> fig.layout % layout reference: <a href="#layout">#layout</a>
ans =
autosize: 0 % layout's 'autosize': <a href="#layout-autosize">#layout-autosize</a>
margin: [1x1 struct] % layout's 'margin': <a href="#layout-margin">#layout-margin</a>
showlegend: 0 % layout's 'showlegend': <a href="#layout-showlegend">#layout-showlegend</a>
width: 840 % layout's 'width': <a href="#layout-width">#layout-width</a>
height: 630 % layout's 'height': <a href="#layout-height">#layout-height</a>
paper_bgcolor: 'rgb(255,255,255)' % layout's 'paper_bgcolor': <a href="#layout-paper_bgcolor">#layout-paper_bgcolor</a>
hovermode: 'closest' % layout's 'hovermode': <a href="#layout-hovermode">#layout-hovermode</a>
plot_bgcolor: 'rgba(0,0,0,0)' % layout's 'plot_bgcolor': <a href="#layout-plot_bgcolor">#layout-plot_bgcolor</a>
xaxis1: [1x1 struct] % layout's 'xaxis': <a href="#layout-xaxis">#layout-xaxis</a>
yaxis1: [1x1 struct] % layout's 'yaxis': <a href="#layout-yaxis">#layout-yaxis</a>
annotations: {[1x1 struct]} % layout's 'annotations': <a href="#layout-annotations">#layout-annotations</a>
>> fig.layout.showlegend = true; % layout's 'showlegend': <a href="#layout-showlegend">#layout-showlegend</a>
>> fig.layout.legend = struct('x', 1, 'y', 1); % Update the legend: <a href="#layout-legend">#layout-legend</a>
>> fig.layout.title = 'Modified plot';
%% Set the filename, and overwrite the plot if it already exists
>> fig.PlotOptions.FileName = 'Customized plot';
>> fig.PlotOptions.FileOpt = 'overwrite';
>> % using offline? Then set fig.PlotOptions.Offline = true;
%% Send to plotly
>> fig.plotly
</pre>
</p>
<hr>
</div>
{% assign quote="'" %}
{% assign array='cell array' %}
{% assign arrays='cell arrays' %}
{% assign object='struct' %}
{% assign 2darray='matrix' %}
{% assign data_array='array' %}
{% assign truestring='true' %}
{% assign falsestring='false' %}
{% include plotschema-reference.html quote=quote array=array arrays=arrays object=object 2darray=2darray data_array=data_array truestring=truestring falsestring=falsestring %}