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

Skip to content

Commit 44a0147

Browse files
fix issue related to plot3 functionality
1 parent 34a21b1 commit 44a0147

File tree

2 files changed

+170
-5
lines changed

2 files changed

+170
-5
lines changed

plotly/plotlyfig_aux/handlegraphics/updateLineseries.m

Lines changed: 166 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,20 @@ function updateLineseries(obj, plotIndex)
139139
obj.PlotOptions.is3d = false; % by default
140140

141141
if isfield(plotData,'ZData')
142+
zData = plotData.ZData;
143+
if isduration(zData) || isdatetime(zData), zData = datenum(zData); end
144+
145+
numbset = unique(zData);
142146

143-
numbset = unique(plotData.ZData);
144-
145-
if any(plotData.ZData) && length(numbset)>1
147+
if any(zData) && length(numbset)>1
146148
%-scatter z-%
147-
obj.data{plotIndex}.z = plotData.ZData;
149+
obj.data{plotIndex}.z = zData;
148150

149151
%-overwrite type-%
150152
obj.data{plotIndex}.type = 'scatter3d';
153+
obj.data{plotIndex}.scene = sprintf('scene%d', xsource);
154+
155+
updateScene(obj, plotIndex);
151156

152157
%-flag to manage 3d plots-%
153158
obj.PlotOptions.is3d = true;
@@ -205,5 +210,162 @@ function updateLineseries(obj, plotIndex)
205210
end
206211

207212
%-------------------------------------------------------------------------%
213+
end
214+
215+
function updateScene(obj, dataIndex)
216+
217+
%-------------------------------------------------------------------------%
218+
219+
%-INITIALIZATIONS-%
220+
axIndex = obj.getAxisIndex(obj.State.Plot(dataIndex).AssociatedAxis);
221+
plotData = get(obj.State.Plot(dataIndex).Handle);
222+
axisData = get(plotData.Parent);
223+
[xSource, ~] = findSourceAxis(obj, axIndex);
224+
scene = eval( sprintf('obj.layout.scene%d', xSource) );
225+
226+
cameraTarget = axisData.CameraTarget;
227+
position = axisData.Position;
228+
aspectRatio = axisData.PlotBoxAspectRatio;
229+
cameraPosition = axisData.CameraPosition;
230+
dataAspectRatio = axisData.DataAspectRatio;
231+
cameraUpVector = axisData.CameraUpVector;
232+
cameraEye = cameraPosition./dataAspectRatio;
233+
normFac = 0.7 * abs(min(cameraEye));
234+
235+
%-------------------------------------------------------------------------%
208236

237+
%-aspect ratio-%
238+
scene.aspectratio.x = 1.0*aspectRatio(1);
239+
scene.aspectratio.y = 1.0*aspectRatio(2);
240+
scene.aspectratio.z = 1.0*aspectRatio(3);
241+
242+
%-camera eye-%
243+
scene.camera.eye.x = cameraEye(1) / normFac;
244+
scene.camera.eye.y = cameraEye(2) / normFac;
245+
scene.camera.eye.z = cameraEye(3) / normFac;
246+
247+
%-camera up-%
248+
scene.camera.up.x = cameraUpVector(1);
249+
scene.camera.up.y = cameraUpVector(2);
250+
scene.camera.up.z = cameraUpVector(3);
251+
252+
%-------------------------------------------------------------------------%
253+
254+
%-scene axis configuration-%
255+
xRange = axisData.XLim;
256+
if isduration(xRange) || isdatetime(xRange), xRange = datenum(xRange); end
257+
scene.xaxis.range = xRange;
258+
259+
yRange = axisData.YLim;
260+
if isduration(yRange) || isdatetime(yRange), yRange = datenum(yRange); end
261+
scene.yaxis.range = yRange;
262+
263+
zRange = axisData.ZLim;
264+
if isduration(zRange) || isdatetime(zRange), zRange = datenum(zRange); end
265+
scene.zaxis.range = zRange;
266+
267+
scene.xaxis.zeroline = false;
268+
scene.yaxis.zeroline = false;
269+
scene.zaxis.zeroline = false;
270+
271+
scene.xaxis.showline = true;
272+
scene.yaxis.showline = true;
273+
scene.zaxis.showline = true;
274+
275+
scene.xaxis.ticklabelposition = 'outside';
276+
scene.yaxis.ticklabelposition = 'outside';
277+
scene.zaxis.ticklabelposition = 'outside';
278+
279+
scene.xaxis.title = axisData.XLabel.String;
280+
scene.yaxis.title = axisData.YLabel.String;
281+
scene.zaxis.title = axisData.ZLabel.String;
282+
283+
scene.xaxis.titlefont.color = 'rgba(0,0,0,1)';
284+
scene.yaxis.titlefont.color = 'rgba(0,0,0,1)';
285+
scene.zaxis.titlefont.color = 'rgba(0,0,0,1)';
286+
scene.xaxis.titlefont.size = axisData.XLabel.FontSize;
287+
scene.yaxis.titlefont.size = axisData.YLabel.FontSize;
288+
scene.zaxis.titlefont.size = axisData.ZLabel.FontSize;
289+
scene.xaxis.titlefont.family = matlab2plotlyfont(axisData.XLabel.FontName);
290+
scene.yaxis.titlefont.family = matlab2plotlyfont(axisData.YLabel.FontName);
291+
scene.zaxis.titlefont.family = matlab2plotlyfont(axisData.ZLabel.FontName);
292+
293+
%-tick labels-%
294+
xTick = axisData.XTick;
295+
if isduration(xTick) || isdatetime(xTick)
296+
xTickChar = char(xTick);
297+
xTickLabel = axisData.XTickLabel;
298+
299+
for n = 1:length(xTickLabel)
300+
for m = 1:size(xTickChar, 1)
301+
if ~isempty(strfind(string(xTickChar(m, :)), xTickLabel{n}))
302+
idx(n) = m;
303+
end
304+
end
305+
end
306+
307+
xTick = datenum(xTick(idx));
308+
end
309+
310+
yTick = axisData.YTick;
311+
if isduration(yTick) || isdatetime(yTick)
312+
yTickChar = char(yTick);
313+
yTickLabel = axisData.YTickLabel;
314+
315+
for n = 1:length(yTickLabel)
316+
for m = 1:size(yTickChar, 1)
317+
if ~isempty(strfind(string(yTickChar(m, :)), yTickLabel{n}))
318+
idx(n) = m;
319+
end
320+
end
321+
end
322+
323+
yTick = datenum(yTick(idx));
324+
end
325+
326+
327+
zTick = axisData.ZTick;
328+
if isduration(zTick) || isdatetime(zTick)
329+
zTickChar = char(zTick);
330+
zTickLabel = axisData.ZTickLabel;
331+
332+
for n = 1:length(zTickLabel)
333+
for m = 1:size(zTickChar, 1)
334+
if ~isempty(strfind(string(zTickChar(m, :)), zTickLabel{n}))
335+
idx(n) = m;
336+
end
337+
end
338+
end
339+
340+
zTick = datenum(zTick(idx));
341+
end
342+
343+
scene.xaxis.tickvals = xTick;
344+
scene.xaxis.ticktext = axisData.XTickLabel;
345+
scene.yaxis.tickvals = yTick;
346+
scene.yaxis.ticktext = axisData.YTickLabel;
347+
scene.zaxis.tickvals = zTick;
348+
scene.zaxis.ticktext = axisData.ZTickLabel;
349+
350+
scene.xaxis.tickcolor = 'rgba(0,0,0,1)';
351+
scene.yaxis.tickcolor = 'rgba(0,0,0,1)';
352+
scene.zaxis.tickcolor = 'rgba(0,0,0,1)';
353+
scene.xaxis.tickfont.size = axisData.FontSize;
354+
scene.yaxis.tickfont.size = axisData.FontSize;
355+
scene.zaxis.tickfont.size = axisData.FontSize;
356+
scene.xaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
357+
scene.yaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
358+
scene.zaxis.tickfont.family = matlab2plotlyfont(axisData.FontName);
359+
360+
%-grid-%
361+
if strcmp(axisData.XGrid, 'off'), scene.xaxis.showgrid = false; end
362+
if strcmp(axisData.YGrid, 'off'), scene.yaxis.showgrid = false; end
363+
if strcmp(axisData.ZGrid, 'off'), scene.zaxis.showgrid = false; end
364+
365+
%-------------------------------------------------------------------------%
366+
367+
%-SET SCENE TO LAYOUT-%
368+
obj.layout = setfield(obj.layout, sprintf('scene%d', xSource), scene);
369+
370+
%-------------------------------------------------------------------------%
209371
end

plotly/plotlyfig_aux/helpers/extractLineMarker.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
%-MARKER SIZE-%
2121
marker.size = line_data.MarkerSize;
2222

23+
if length(marker.size) == 1
24+
marker.size = 0.6*marker.size;
25+
end
26+
2327
%-------------------------------------------------------------------------%
2428

2529
%-MARKER SYMBOL-%
@@ -28,7 +32,6 @@
2832
switch line_data.Marker
2933
case '.'
3034
marksymbol = 'circle';
31-
marker.size = 0.4*line_data.MarkerSize;
3235
case 'o'
3336
marksymbol = 'circle';
3437
case 'x'

0 commit comments

Comments
 (0)