Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ddecfc

Browse files
Fix polarAxis.angularaxis title overwritten by polarAxis.radialaxis title
1 parent 5376988 commit 8ddecfc

File tree

3 files changed

+86
-67
lines changed

3 files changed

+86
-67
lines changed

plotly/Test_plotlyfig.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,35 @@ function testPolarHistogramPlotData(tc)
396396
), AbsTol=1e-15);
397397
end
398398

399+
function testEasyToUsePolarPlotData(tc)
400+
fig = figure("Visible","off");
401+
ezpolar("1+cos(theta)")
402+
403+
p = plotlyfig(fig,"visible","off","treatAs",'ezpolar');
404+
405+
tc.verifyNumElements(p.data, 1);
406+
tc.verifyEqual(rmfield(p.data{1},["r" "theta"]), struct( ...
407+
"type", "scatterpolar", ...
408+
"subplot", "polar2", ...
409+
"visible", true, ...
410+
"name", '', ...
411+
"mode", 'lines', ...
412+
"line", struct( ...
413+
"color", "rgb(0,114,189)", ...
414+
"width", 0.75, ...
415+
"dash", 'solid' ...
416+
), ...
417+
"marker", struct( ...
418+
"size", 3.6, ...
419+
"line", struct( ...
420+
"width", 0.5 ...
421+
), ...
422+
"color", "rgb(0,114,189)" ...
423+
), ...
424+
"showlegend", false ...
425+
), AbsTol=1e-15);
426+
end
427+
399428
function testLogLogPlot(tc)
400429
fig = figure("Visible","off");
401430
zeta = 0.5; % damping factor

plotly/plotlyfig_aux/core/updateData.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@
202202
end
203203

204204
% Plotly requires x and y to be iterable
205-
if isscalar(obj.data{dataIndex}.x)
205+
if isfield(obj.data{dataIndex},"x") && isscalar(obj.data{dataIndex}.x)
206206
obj.data{dataIndex}.x = {obj.data{dataIndex}.x};
207207
end
208-
if isscalar(obj.data{dataIndex}.y)
208+
if isfield(obj.data{dataIndex},"y") && isscalar(obj.data{dataIndex}.y)
209209
obj.data{dataIndex}.y = {obj.data{dataIndex}.y};
210210
end
211211

plotly/plotlyfig_aux/handlegraphics/updateLineseries.m

Lines changed: 55 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
if isPolar
3939
data.type = "scatterpolar";
40-
updateDefaultPolaraxes(obj, plotIndex)
4140
data.subplot = sprintf("polar%d", xSource+1);
41+
obj.layout.(data.subplot) = updateDefaultPolarAxes(obj, plotIndex);
4242
elseif ~isPlot3D
4343
data.type = "scatter";
4444
data.xaxis = "x" + xSource;
@@ -213,87 +213,77 @@ function updateScene(obj, dataIndex)
213213
obj.layout.("scene" + xsource) = scene;
214214
end
215215

216-
function updateDefaultPolaraxes(obj, plotIndex)
216+
function polarAxis = updateDefaultPolarAxes(obj, plotIndex)
217217
%-INITIALIZATIONS-%
218-
axIndex = obj.getAxisIndex(obj.State.Plot(plotIndex).AssociatedAxis);
219-
xSource = findSourceAxis(obj, axIndex);
220218
plotData = obj.State.Plot(plotIndex).Handle;
221219
axisData = plotData.Parent;
222220

223221
thetaAxis = axisData.XAxis;
224222
rAxis = axisData.YAxis;
223+
thetaLabel = thetaAxis.Label;
225224

226225
%-set domain plot-%
227226
xo = axisData.Position(1);
228227
yo = axisData.Position(2);
229228
w = axisData.Position(3);
230229
h = axisData.Position(4);
231230

232-
polarAxis.domain.x = min([xo xo + w], 1);
233-
polarAxis.domain.y = min([yo yo + h], 1);
234-
235231
tickValues = rAxis.TickValues;
236232
tickValues = tickValues(find(tickValues==0) + 1 : end);
237-
238-
%-SET ANGULAR AXIS-%
233+
rLabel = rAxis.Label;
239234

240235
gridColor = getStringColor(255*axisData.GridColor, axisData.GridAlpha);
241236
gridWidth = axisData.LineWidth;
242237

243-
polarAxis.angularaxis.ticklen = 0;
244-
polarAxis.angularaxis.autorange = true;
245-
polarAxis.angularaxis.linecolor = gridColor;
246-
polarAxis.angularaxis.gridwidth = gridWidth;
247-
polarAxis.angularaxis.gridcolor = gridColor;
248-
polarAxis.angularaxis.rotation = -axisData.View(1);
249-
250-
%-axis tick-%
251-
polarAxis.angularaxis.showticklabels = true;
252-
polarAxis.angularaxis.nticks = 16;
253-
polarAxis.angularaxis.tickfont.size = thetaAxis.FontSize;
254-
polarAxis.angularaxis.tickfont.color = getStringColor(...
255-
round(255*thetaAxis.Color));
256-
polarAxis.angularaxis.tickfont.family = matlab2plotlyfont(...
257-
thetaAxis.FontName);
258-
259-
%-axis label-%
260-
thetaLabel = thetaAxis.Label;
261-
262-
polarAxis.angularaxis.title.text = thetaLabel.String;
263-
polarAxis.radialaxis.title.font.size = thetaLabel.FontSize;
264-
polarAxis.radialaxis.title.font.color = getStringColor(...
265-
round(255*thetaLabel.Color));
266-
polarAxis.radialaxis.title.font.family = matlab2plotlyfont(...
267-
thetaLabel.FontName);
268-
269-
%-SET RADIAL AXIS-%
270-
271-
polarAxis.radialaxis.ticklen = 0;
272-
polarAxis.radialaxis.range = [0, tickValues(end)];
273-
polarAxis.radialaxis.showline = false;
274-
275-
polarAxis.radialaxis.angle = 80;
276-
polarAxis.radialaxis.tickangle = 80;
277-
278-
polarAxis.radialaxis.gridwidth = gridWidth;
279-
polarAxis.radialaxis.gridcolor = gridColor;
280-
281-
%-axis tick-%
282-
polarAxis.radialaxis.showticklabels = true;
283-
polarAxis.radialaxis.tickvals = tickValues;
284-
polarAxis.radialaxis.tickfont.size = rAxis.FontSize;
285-
polarAxis.radialaxis.tickfont.color = getStringColor(round(...
286-
255*rAxis.Color));
287-
polarAxis.radialaxis.tickfont.family = matlab2plotlyfont(...
288-
rAxis.FontName);
289-
290-
rLabel = rAxis.Label;
291-
polarAxis.radialaxis.title.text = rLabel.String;
292-
polarAxis.radialaxis.title.font.size = rLabel.FontSize;
293-
polarAxis.radialaxis.title.font.color = getStringColor(round(...
294-
255*rLabel.Color));
295-
polarAxis.radialaxis.title.font.family = matlab2plotlyfont(...
296-
rLabel.FontName);
297-
298-
obj.layout.(sprintf('polar%d', xSource+1)) = polarAxis;
238+
polarAxis.domain = struct( ...
239+
"x", min([xo xo + w], 1), ...
240+
"y", min([yo yo + h], 1) ...
241+
);
242+
polarAxis.angularaxis = struct(...
243+
"ticklen", 0, ...
244+
"autorange", true, ...
245+
"linecolor", gridColor, ...
246+
"gridwidth", gridWidth, ...
247+
"gridcolor", gridColor, ...
248+
"rotation", -axisData.View(1), ...
249+
"showticklabels", true, ...
250+
"nticks", 16, ...
251+
"tickfont", struct( ...
252+
"size", thetaAxis.FontSize, ...
253+
"color", getStringColor(round(255*thetaAxis.Color)), ...
254+
"family", matlab2plotlyfont(thetaAxis.FontName) ...
255+
), ...
256+
"title", struct( ...
257+
"text", thetaLabel.String, ...
258+
"font", struct( ...
259+
"size", thetaLabel.FontSize, ...
260+
"color", getStringColor(round(255*thetaLabel.Color)), ...
261+
"family", matlab2plotlyfont(thetaLabel.FontName) ...
262+
) ...
263+
) ...
264+
);
265+
polarAxis.radialaxis = struct( ...
266+
"ticklen", 0, ...
267+
"range", [0, tickValues(end)], ...
268+
"showline", false, ...
269+
"angle", 80, ...
270+
"tickangle", 80, ...
271+
"gridwidth", gridWidth, ...
272+
"gridcolor", gridColor, ...
273+
"showticklabels", true, ...
274+
"tickvals", tickValues, ...
275+
"tickfont", struct( ...
276+
"size", rAxis.FontSize, ...
277+
"color", getStringColor(round(255*rAxis.Color)), ...
278+
"family", matlab2plotlyfont(rAxis.FontName) ...
279+
), ...
280+
"title", struct( ...
281+
"text", rLabel.String, ...
282+
"font", struct( ...
283+
"size", rLabel.FontSize, ...
284+
"color", getStringColor(round(255*rLabel.Color)), ...
285+
"family", matlab2plotlyfont(rLabel.FontName) ...
286+
) ...
287+
) ...
288+
);
299289
end

0 commit comments

Comments
 (0)