Skip to content

Commit 045f0d1

Browse files
improve aspect ratio and camera eye using surfc matlab function
1 parent 754a841 commit 045f0d1

File tree

1 file changed

+55
-125
lines changed

1 file changed

+55
-125
lines changed

plotly/plotlyfig_aux/handlegraphics/updateContourProjection.m

Lines changed: 55 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
axis_data = get(obj.State.Plot(contourIndex).AssociatedAxis);
1111

1212
%-PLOT DATA STRUCTURE- %
13-
contour_data = get(obj.State.Plot(contourIndex).Handle)
13+
contour_data = get(obj.State.Plot(contourIndex).Handle);
1414

1515
%-CHECK FOR MULTIPLE AXES-%
1616
[xsource, ysource] = findSourceAxis(obj,axIndex);
@@ -40,68 +40,29 @@
4040
xdata = contour_data.XData;
4141
ydata = contour_data.YData;
4242
zdata = contour_data.ZData;
43-
44-
if isvector(zdata)
45-
46-
%-contour type-%
47-
obj.data{contourIndex}.type = 'contour';
4843

49-
%-contour x data-%
50-
if ~isvector(x)
51-
obj.data{contourIndex}.xdata = xdata(1,:);
52-
else
53-
obj.data{contourIndex}.xdata = xdata;
54-
end
44+
%-contour type-%
45+
obj.data{contourIndex}.type = 'surface';
5546

56-
%-contour y data-%
57-
if ~isvector(y)
58-
obj.data{contourIndex}.ydata = ydata';
59-
else
60-
obj.data{contourIndex}.ydata = ydata';
61-
end
62-
63-
%-contour z data-%
64-
obj.data{contourIndex}.z = zdata;
65-
66-
else
67-
68-
%-contour type-%
69-
obj.data{contourIndex}.type = 'surface';
70-
71-
%-contour x and y data
72-
% [xmesh, ymesh] = meshgrid(xdata, ydata);
73-
obj.data{contourIndex}.x = xdata;
74-
obj.data{contourIndex}.y = ydata;
75-
76-
%-contour z data-%
77-
obj.data{contourIndex}.z = zdata;%-2*ones(size(zdata));
78-
79-
%-setting for contour lines z-direction-%
80-
obj.data{contourIndex}.contours.z.start = contour_data.LevelList(1);
81-
obj.data{contourIndex}.contours.z.end = contour_data.LevelList(end);
82-
obj.data{contourIndex}.contours.z.size = contour_data.LevelStep;
83-
obj.data{contourIndex}.contours.z.show = true;
84-
obj.data{contourIndex}.contours.z.usecolormap = true;
85-
obj.data{contourIndex}.hidesurface = true;
86-
obj.data{contourIndex}.surfacecolor = zdata;
87-
88-
obj.data{contourIndex}.contours.z.project.x = true;
89-
obj.data{contourIndex}.contours.z.project.y = true;
90-
obj.data{contourIndex}.contours.z.project.z = true;
91-
92-
end
47+
%-contour x and y data
48+
obj.data{contourIndex}.x = xdata;
49+
obj.data{contourIndex}.y = ydata;
9350

94-
%-------------------------------------------------------------------------%
51+
%-contour z data-%
52+
obj.data{contourIndex}.z = zdata;%-2*ones(size(zdata));
9553

96-
%-contour x type-%
54+
%-setting for contour lines z-direction-%
55+
obj.data{contourIndex}.contours.z.start = contour_data.LevelList(1);
56+
obj.data{contourIndex}.contours.z.end = contour_data.LevelList(end);
57+
obj.data{contourIndex}.contours.z.size = contour_data.LevelStep;
58+
obj.data{contourIndex}.contours.z.show = true;
59+
obj.data{contourIndex}.contours.z.usecolormap = true;
60+
obj.data{contourIndex}.hidesurface = true;
61+
obj.data{contourIndex}.surfacecolor = zdata;
9762

98-
obj.data{contourIndex}.xtype = 'array';
99-
100-
%-------------------------------------------------------------------------%
101-
102-
%-contour y type-%
103-
104-
obj.data{contourIndex}.ytype = 'array';
63+
obj.data{contourIndex}.contours.z.project.x = true;
64+
obj.data{contourIndex}.contours.z.project.y = true;
65+
obj.data{contourIndex}.contours.z.project.z = true;
10566

10667
%-------------------------------------------------------------------------%
10768

@@ -116,21 +77,6 @@
11677

11778
%-------------------------------------------------------------------------%
11879

119-
%-zauto-%
120-
obj.data{contourIndex}.zauto = false;
121-
122-
%-------------------------------------------------------------------------%
123-
124-
%-zmin-%
125-
obj.data{contourIndex}.zmin = axis_data.CLim(1);
126-
127-
%-------------------------------------------------------------------------%
128-
129-
%-zmax-%
130-
obj.data{contourIndex}.zmax = axis_data.CLim(2);
131-
132-
%-------------------------------------------------------------------------%
133-
13480
%-colorscale (ASSUMES PATCH CDATAMAP IS 'SCALED')-%
13581
colormap = figure_data.Colormap;
13682

@@ -144,69 +90,53 @@
14490
%-contour reverse scale-%
14591
obj.data{contourIndex}.reversescale = false;
14692

147-
%-------------------------------------------------------------------------%
148-
149-
%-autocontour-%
150-
obj.data{contourIndex}.autocontour = false;
93+
%---------------------------------------------------------------------%
15194

152-
%-------------------------------------------------------------------------%
95+
%-aspect ratio-%
96+
ar = obj.PlotOptions.AspectRatio;
15397

154-
%-contour contours-%
98+
if ~isempty(ar)
99+
if ischar(ar)
100+
obj.layout.scene.aspectmode = ar;
101+
elseif isvector(ar) && length(ar) == 3
102+
xar = ar(1);
103+
yar = ar(2);
104+
zar = ar(3);
105+
end
106+
else
155107

156-
%-coloring-%
157-
switch contour_data.Fill
158-
case 'off'
159-
obj.data{contourIndex}.contours.coloring = 'lines';
160-
case 'on'
161-
obj.data{contourIndex}.contours.coloring = 'fill';
108+
%-define as default-%
109+
xar = max(xdata(:));
110+
yar = max(ydata(:));
111+
xyar = max([xar, yar]);
112+
zar = 0.6*xyar;
162113
end
163114

164-
%-start-%
165-
obj.data{contourIndex}.contours.start = contour_data.TextList(1);
115+
obj.layout.scene.aspectratio.x = xyar;
116+
obj.layout.scene.aspectratio.y = xyar;
117+
obj.layout.scene.aspectratio.z = zar;
166118

167-
%-end-%
168-
obj.data{contourIndex}.contours.end = contour_data.TextList(end);
119+
%---------------------------------------------------------------------%
169120

170-
%-step-%
171-
obj.data{contourIndex}.contours.size = diff(contour_data.TextList(1:2));
121+
%-camera eye-%
122+
ey = obj.PlotOptions.CameraEye;
172123

173-
%-------------------------------------------------------------------------%
174-
175-
if(~strcmp(contour_data.LineStyle,'none'))
176-
177-
%-contour line colour-%
178-
if isnumeric(contour_data.LineColor)
179-
col = 255*contour_data.LineColor;
180-
obj.data{contourIndex}.line.color = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
181-
else
182-
obj.data{contourIndex}.line.color = 'rgba(0,0,0,0)';
183-
end
184-
185-
%-contour line width-%
186-
obj.data{contourIndex}.line.width = contour_data.LineWidth;
187-
188-
%-contour line dash-%
189-
switch contour_data.LineStyle
190-
case '-'
191-
LineStyle = 'solid';
192-
case '--'
193-
LineStyle = 'dash';
194-
case ':'
195-
LineStyle = 'dot';
196-
case '-.'
197-
LineStyle = 'dashdot';
124+
if ~isempty(ey)
125+
if isvector(ey) && length(ey) == 3
126+
obj.layout.scene.camera.eye.x = ey(1);
127+
obj.layout.scene.camera.eye.y = ey(2);
128+
obj.layout.scene.camera.eye.z = ey(3);
198129
end
199-
200-
obj.data{contourIndex}.line.dash = LineStyle;
201-
202-
%-contour smoothing-%
203-
obj.data{contourIndex}.line.smoothing = 0;
204-
205130
else
131+
132+
%-define as default-%
133+
xey = - xyar; if xey>0 xfac = -0.2; else xfac = 0.2; end
134+
yey = - xyar; if yey>0 yfac = -0.2; else yfac = 0.2; end
135+
if zar>0 zfac = 0.2; else zfac = -0.2; end
206136

207-
%-contours showlines-%
208-
obj.data{contourIndex}.contours.showlines = false;
209-
137+
obj.layout.scene.camera.eye.x = xey + xfac*xey;
138+
obj.layout.scene.camera.eye.y = yey + yfac*yey;
139+
obj.layout.scene.camera.eye.z = zar + zfac*zar;
210140
end
211141

212142
%-------------------------------------------------------------------------%

0 commit comments

Comments
 (0)