|
3 | 3 | % axisData is the data extracted from the figure, axisName take the |
4 | 4 | % values "x" "y" or "z" |
5 | 5 |
|
6 | | - %=====================================================================% |
7 | | - % |
8 | | - % AXIS INITIALIZATION |
9 | | - % |
10 | | - %=====================================================================% |
11 | | - |
12 | | - %-general axis settings-% |
13 | | - axisColor = round(255 * axisData.(axisName + "Color")); |
14 | | - axisColor = getStringColor(axisColor); |
| 6 | + axisColor = getStringColor(round(255 * axisData.(axisName + "Color"))); |
15 | 7 | lineWidth = max(1, ... |
16 | 8 | axisData.LineWidth*obj.PlotlyDefaults.AxisLineIncreaseFactor); |
17 | 9 |
|
|
22 | 14 | exponentFormat = 0; |
23 | 15 | end |
24 | 16 |
|
25 | | - axis.side = axisData.(axisName + "AxisLocation"); |
26 | | - axis.zeroline = false; |
27 | | - axis.autorange = false; |
28 | | - axis.linecolor = axisColor; |
29 | | - axis.linewidth = lineWidth; |
30 | | - axis.exponentformat = obj.PlotlyDefaults.ExponentFormat; |
31 | | - |
32 | | - %-general tick settings-% |
33 | | - tickRotation = axisData.(axisName + "TickLabelRotation"); |
34 | | - tickLength = min(obj.PlotlyDefaults.MaxTickLength,... |
35 | | - max(axisData.TickLength(1)*axisData.Position(3)*obj.layout.width,... |
| 17 | + tickLength = min(obj.PlotlyDefaults.MaxTickLength, ... |
| 18 | + max(axisData.TickLength(1)*axisData.Position(3)*obj.layout.width, ... |
36 | 19 | axisData.TickLength(1)*axisData.Position(4)*obj.layout.height)); |
37 | 20 |
|
38 | | - axis.tickfont.size = axisData.FontSize; |
39 | | - axis.tickfont.family = matlab2plotlyfont(axisData.FontName); |
40 | | - axis.tickfont.color = axisColor; |
41 | | - |
42 | | - axis.ticklen = tickLength; |
43 | | - axis.tickcolor = axisColor; |
44 | | - axis.tickwidth = lineWidth; |
45 | | - axis.tickangle = -tickRotation; |
| 21 | + axis = struct(... |
| 22 | + "side", axisData.(axisName + "AxisLocation"), ... |
| 23 | + "zeroline", false, ... |
| 24 | + "autorange", false, ... |
| 25 | + "linecolor", axisColor, ... |
| 26 | + "linewidth", lineWidth, ... |
| 27 | + "exponentformat", obj.PlotlyDefaults.ExponentFormat, ... |
| 28 | + "tickfont", struct( ... |
| 29 | + "size", axisData.FontSize, ... |
| 30 | + "family", matlab2plotlyfont(axisData.FontName), ... |
| 31 | + "color", axisColor ... |
| 32 | + ), ... |
| 33 | + "ticklen", tickLength, ... |
| 34 | + "tickcolor", axisColor, ... |
| 35 | + "tickwidth", lineWidth, ... |
| 36 | + "tickangle", -axisData.(axisName + "TickLabelRotation"), ... |
| 37 | + "type", axisData.(axisName + "Scale") ... |
| 38 | + ); |
46 | 39 |
|
47 | 40 | switch axisData.TickDir |
48 | 41 | case "in" |
|
51 | 44 | axis.ticks = "outside"; |
52 | 45 | end |
53 | 46 |
|
54 | | - %-set axis grid-% |
55 | 47 | isGrid = axisData.(axisName + "Grid"); |
56 | 48 | isMinorGrid = axisData.(axisName + "MinorGrid"); |
57 | | - |
58 | 49 | if strcmp(isGrid, "on") || strcmp(isMinorGrid, "on") |
59 | 50 | axis.showgrid = true; |
60 | 51 | axis.gridwidth = lineWidth; |
61 | 52 | else |
62 | 53 | axis.showgrid = false; |
63 | 54 | end |
64 | 55 |
|
65 | | - %-axis grid color-% |
66 | 56 | if isprop(axisData, "GridColor") && isprop(axisData, "GridAlpha") |
67 | 57 | axis.gridcolor = getStringColor( ... |
68 | 58 | round(255*axisData.GridColor), axisData.GridAlpha); |
69 | 59 | else |
70 | 60 | axis.gridcolor = axisColor; |
71 | 61 | end |
72 | 62 |
|
73 | | - %-axis type-% |
74 | | - axis.type = axisData.(axisName + "Scale"); |
75 | | - |
76 | | - %=====================================================================% |
77 | | - % |
78 | | - % SET TICK LABELS |
79 | | - % |
80 | | - %=====================================================================% |
81 | | - |
82 | | - %-get tick label data-% |
83 | 63 | tickLabels = axisData.(axisName + "TickLabel"); |
84 | 64 | tickValues = axisData.(axisName + "Tick"); |
85 | 65 |
|
|
96 | 76 | end |
97 | 77 | assert(isequal(numel(tickLabels),numel(tickValues))); |
98 | 78 |
|
99 | | - %-there is not tick label case-% |
100 | | - if isempty(tickValues) |
| 79 | + if isempty(tickValues) % There are no tick labels |
101 | 80 | axis.ticks = ""; |
102 | 81 | axis.showticklabels = false; |
103 | 82 | axis.autorange = true; |
|
108 | 87 | case "off" |
109 | 88 | axis.mirror = false; |
110 | 89 | end |
111 | | - else %-there is tick labels case-% |
112 | | - %-set tick values-% |
| 90 | + else % There are tick labels |
113 | 91 | axis.showticklabels = true; |
114 | 92 | axis.tickmode = "array"; |
115 | 93 |
|
|
146 | 124 | axis.type = "date"; |
147 | 125 | if isprop(axisData, "XTickLabelMode") ... |
148 | 126 | && isequal(axisData.XTickLabelMode, "auto") |
149 | | - % default matlab xticks are unreliable for datetime. eg. |
150 | | - % fig = figure(visible="off"); |
151 | | - % dt = datetime(2013,3,2):datetime(2020,1,1); |
152 | | - % plot(dt,randi([-10 10],numel(dt),1)'); |
153 | | - % isequal(numel(fig.Children.XTick),numel(fig.Children.XTickLabel)) % returns false |
154 | 127 | axis.autotick = true; |
155 | 128 | tickLabels = {}; |
156 | | - tickValues = []; %#ok<NASGU> |
157 | 129 | end |
158 | 130 |
|
159 | 131 | elseif iscategorical(axisLim) |
|
163 | 135 | axis.autorange = true; |
164 | 136 | end |
165 | 137 |
|
166 | | - %-box setting-% |
167 | 138 | switch axisData.Box |
168 | 139 | case "on" |
169 | 140 | axis.mirror = "ticks"; |
170 | 141 | case "off" |
171 | 142 | axis.mirror = false; |
172 | 143 | end |
173 | 144 |
|
174 | | - %-set tick labels by using tick texts-% |
175 | 145 | if ~isempty(tickLabels) |
176 | 146 | axis.ticktext = tickLabels; |
177 | 147 | end |
178 | 148 | end |
179 | 149 |
|
180 | | - %-axis direction-% |
181 | 150 | axisDirection = axisData.(axisName + "Dir"); |
182 | 151 |
|
183 | 152 | if strcmp(axisDirection, "reverse") |
184 | 153 | axis.range = [axis.range(2) axis.range(1)]; |
185 | 154 | end |
186 | 155 |
|
187 | | - %=====================================================================% |
188 | | - % |
189 | | - % SET AXIS LABEL |
190 | | - % |
191 | | - %=====================================================================% |
192 | | - |
193 | | - %-get label data-% |
194 | 156 | label = axisData.(axisName + "Label"); |
195 | 157 | labelData = label; |
196 | 158 |
|
197 | 159 | %-STANDARDIZE UNITS-% |
198 | 160 | fontunits = label.FontUnits; |
199 | 161 | label.FontUnits = "points"; |
200 | 162 |
|
201 | | - %-title label settings-% |
202 | 163 | if ~isempty(labelData.String) |
203 | 164 | axis.title = parseString(labelData.String,labelData.Interpreter); |
204 | 165 | end |
|
210 | 171 | %-REVERT UNITS-% |
211 | 172 | label.FontUnits = fontunits; |
212 | 173 |
|
213 | | - %-set visibility conditions-% |
214 | 174 | if strcmp(axisData.Visible, "on") |
215 | 175 | axis.showline = true; |
216 | 176 | else |
|
0 commit comments