Skip to content

Commit 6dc5868

Browse files
Merge pull request #351 from plotly/contour3issues_RatioAspect_CameraEye
Contour3issues ratio aspect camera eye
2 parents e8803ab + 4d787c6 commit 6dc5868

File tree

2 files changed

+155
-88
lines changed

2 files changed

+155
-88
lines changed

Diff for: plotly/plotlyfig.m

+8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
obj.PlotOptions.Image3D = false;
6565
obj.PlotOptions.ContourProjection = false;
6666
obj.PlotOptions.AxisEqual = false;
67+
obj.PlotOptions.AspectRatio = [];
68+
obj.PlotOptions.CameraEye = [];
6769

6870
% offline options
6971
obj.PlotOptions.Offline = true;
@@ -209,6 +211,12 @@
209211
if(strcmpi(varargin{a},'AxisEqual'))
210212
obj.PlotOptions.AxisEqual = varargin{a+1};
211213
end
214+
if(strcmpi(varargin{a},'AspectRatio'))
215+
obj.PlotOptions.AspectRatio = varargin{a+1};
216+
end
217+
if(strcmpi(varargin{a},'CameraEye'))
218+
obj.PlotOptions.CameraEye = varargin{a+1};
219+
end
212220
end
213221
end
214222

Diff for: plotly/plotlyfig_aux/handlegraphics/updateContourgroup.m

+147-88
Original file line numberDiff line numberDiff line change
@@ -82,133 +82,67 @@
8282

8383
if isvector(zdata)
8484

85+
%---------------------------------------------------------------------%
86+
8587
%-contour type-%
8688
obj.data{contourIndex}.type = 'contour';
8789

90+
%---------------------------------------------------------------------%
91+
8892
%-contour x data-%
8993
if ~isvector(x)
9094
obj.data{contourIndex}.xdata = xdata(1,:);
9195
else
9296
obj.data{contourIndex}.xdata = xdata;
9397
end
94-
98+
99+
%---------------------------------------------------------------------%
100+
95101
%-contour y data-%
96102
if ~isvector(y)
97103
obj.data{contourIndex}.ydata = ydata';
98104
else
99105
obj.data{contourIndex}.ydata = ydata';
100106
end
101107

102-
%-contour z data-%
103-
obj.data{contourIndex}.z = zdata;
104-
105-
else
106-
107-
%-contour type-%
108-
obj.data{contourIndex}.type = 'surface';
109-
110-
%-contour x and y data
111-
if isvector(xdata)
112-
[xdata, ydata] = meshgrid(xdata, ydata);
113-
end
114-
obj.data{contourIndex}.x = xdata;
115-
obj.data{contourIndex}.y = ydata;
108+
%---------------------------------------------------------------------%
116109

117110
%-contour z data-%
118111
obj.data{contourIndex}.z = zdata;
119112

120-
%-setting for contour lines z-direction-%
121-
if length(contour_data.LevelList) > 1
122-
zstart = contour_data.LevelList(1);
123-
zend = contour_data.LevelList(end);
124-
zsize = mean(diff(contour_data.LevelList));
125-
else
126-
zstart = contour_data.LevelList(1) - 1e-3;
127-
zend = contour_data.LevelList(end) + 1e-3;
128-
zsize = 2e-3;
129-
end
130-
l = 30;
131-
obj.data{contourIndex}.contours.z.start = zstart;
132-
obj.data{contourIndex}.contours.z.end = zend;
133-
obj.data{contourIndex}.contours.z.size = zsize;
134-
obj.data{contourIndex}.contours.z.show = true;
135-
obj.data{contourIndex}.contours.z.usecolormap = true;
136-
obj.data{contourIndex}.contours.z.width = contour_data.LineWidth;
137-
obj.data{contourIndex}.hidesurface = true;
138-
139-
end
140-
141-
%-------------------------------------------------------------------------%
142-
143-
if isvector(zdata)
113+
%---------------------------------------------------------------------%
144114

145115
%-contour x type-%
146116

147117
obj.data{contourIndex}.xtype = 'array';
148118

149-
%-------------------------------------------------------------------------%
119+
%---------------------------------------------------------------------%
150120

151121
%-contour y type-%
152122

153123
obj.data{contourIndex}.ytype = 'array';
154124

155-
end
156-
157-
%-------------------------------------------------------------------------%
158-
159-
%-contour visible-%
160-
161-
obj.data{contourIndex}.visible = strcmp(contour_data.Visible,'on');
162-
163-
%-------------------------------------------------------------------------%
164-
165-
%-contour showscale-%
166-
obj.data{contourIndex}.showscale = false;
167-
168-
%-------------------------------------------------------------------------%
169-
170-
if isvector(zdata)
125+
%---------------------------------------------------------------------%
126+
171127
%-zauto-%
172128
obj.data{contourIndex}.zauto = false;
173129

174-
%-------------------------------------------------------------------------%
130+
%---------------------------------------------------------------------%
175131

176132
%-zmin-%
177133
obj.data{contourIndex}.zmin = axis_data.CLim(1);
178134

179-
%-------------------------------------------------------------------------%
135+
%---------------------------------------------------------------------%
180136

181137
%-zmax-%
182138
obj.data{contourIndex}.zmax = axis_data.CLim(2);
183-
end
184-
185-
%-------------------------------------------------------------------------%
186-
187-
%-colorscale (ASSUMES PATCH CDATAMAP IS 'SCALED')-%
188-
colormap = figure_data.Colormap;
189-
190-
for c = 1:size((colormap),1)
191-
col = 255*(colormap(c,:));
192-
obj.data{contourIndex}.colorscale{c} = {(c-1)/(size(colormap,1)-1), ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']};
193-
end
194-
195-
%-------------------------------------------------------------------------%
196-
197-
%-contour reverse scale-%
198-
obj.data{contourIndex}.reversescale = false;
199-
200-
%-------------------------------------------------------------------------%
201-
202-
if isvector(zdata)
139+
140+
%---------------------------------------------------------------------%
203141

204142
%-autocontour-%
205143
obj.data{contourIndex}.autocontour = false;
206144

207-
end
208-
209-
%-------------------------------------------------------------------------%
210-
211-
if isvector(zdata)
145+
%---------------------------------------------------------------------%
212146

213147
%-contour contours-%
214148

@@ -229,11 +163,9 @@
229163
%-step-%
230164
obj.data{contourIndex}.contours.size = diff(contour_data.TextList(1:2));
231165

232-
end
233-
234-
%-------------------------------------------------------------------------%
235-
236-
if isvector(zdata)
166+
%---------------------------------------------------------------------%
167+
168+
%-contour line setting-%
237169
if(~strcmp(contour_data.LineStyle,'none'))
238170

239171
%-contour line colour-%
@@ -270,10 +202,137 @@
270202
obj.data{contourIndex}.contours.showlines = false;
271203

272204
end
205+
206+
%---------------------------------------------------------------------%
207+
208+
else
209+
210+
%---------------------------------------------------------------------%
211+
212+
%-contour type-%
213+
obj.data{contourIndex}.type = 'surface';
214+
215+
%---------------------------------------------------------------------%
216+
217+
%-contour x and y data
218+
if isvector(xdata)
219+
[xdata, ydata] = meshgrid(xdata, ydata);
220+
end
221+
obj.data{contourIndex}.x = xdata;
222+
obj.data{contourIndex}.y = ydata;
223+
224+
%---------------------------------------------------------------------%
225+
226+
%-contour z data-%
227+
obj.data{contourIndex}.z = zdata;
228+
229+
%---------------------------------------------------------------------%
230+
231+
%-setting for contour lines z-direction-%
232+
if length(contour_data.LevelList) > 1
233+
zstart = contour_data.LevelList(1);
234+
zend = contour_data.LevelList(end);
235+
zsize = mean(diff(contour_data.LevelList));
236+
else
237+
zstart = contour_data.LevelList(1) - 1e-3;
238+
zend = contour_data.LevelList(end) + 1e-3;
239+
zsize = 2e-3;
240+
end
241+
242+
obj.data{contourIndex}.contours.z.start = zstart;
243+
obj.data{contourIndex}.contours.z.end = zend;
244+
obj.data{contourIndex}.contours.z.size = zsize;
245+
obj.data{contourIndex}.contours.z.show = true;
246+
obj.data{contourIndex}.contours.z.usecolormap = true;
247+
obj.data{contourIndex}.contours.z.width = 2*contour_data.LineWidth;
248+
obj.data{contourIndex}.hidesurface = true;
249+
250+
%---------------------------------------------------------------------%
251+
252+
%-colorscale-%
253+
colormap = figure_data.Colormap;
254+
255+
for c = 1:size((colormap),1)
256+
col = 255*(colormap(c,:));
257+
obj.data{contourIndex}.colorscale{c} = {(c-1)/(size(colormap,1)-1), ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']};
258+
end
259+
260+
%---------------------------------------------------------------------%
261+
262+
%-aspect ratio-%
263+
ar = obj.PlotOptions.AspectRatio;
264+
265+
if ~isempty(ar)
266+
if ischar(ar)
267+
obj.layout.scene.aspectmode = ar;
268+
elseif isvector(ar) && length(ar) == 3
269+
xar = ar(1);
270+
yar = ar(2);
271+
zar = ar(3);
272+
end
273+
else
274+
275+
%-define as default-%
276+
xar = max(xdata(:));
277+
yar = max(ydata(:));
278+
zar = 0.7*max([xar, yar]);
279+
end
280+
281+
obj.layout.scene.aspectratio.x = xar;
282+
obj.layout.scene.aspectratio.y = yar;
283+
obj.layout.scene.aspectratio.z = zar;
284+
285+
%---------------------------------------------------------------------%
286+
287+
%-camera eye-%
288+
ey = obj.PlotOptions.CameraEye;
289+
290+
if ~isempty(ey)
291+
if isvector(ey) && length(ey) == 3
292+
obj.layout.scene.camera.eye.x = ey(1);
293+
obj.layout.scene.camera.eye.y = ey(2);
294+
obj.layout.scene.camera.eye.z = ey(3);
295+
end
296+
else
297+
298+
%-define as default-%
299+
xey = min(xdata(:)); if xey>0 xfac = -0.2; else xfac = 0.2; end
300+
yey = min(ydata(:)); if yey>0 yfac = -0.2; else yfac = 0.2; end
301+
if zar>0 zfac = -0.15; else zfac = 0.15; end
302+
303+
obj.layout.scene.camera.eye.x = xey + xfac*xey;
304+
obj.layout.scene.camera.eye.y = yey + yfac*yey;
305+
obj.layout.scene.camera.eye.z = zar + yfac*zar;
306+
end
307+
308+
%---------------------------------------------------------------------%
309+
310+
%-zerolines hidded-%
311+
obj.layout.scene.xaxis.zeroline = false;
312+
obj.layout.scene.yaxis.zeroline = false;
313+
obj.layout.scene.zaxis.zeroline = false;
314+
315+
%---------------------------------------------------------------------%
316+
273317
end
274318

275319
%-------------------------------------------------------------------------%
276320

321+
%-contour visible-%
322+
obj.data{contourIndex}.visible = strcmp(contour_data.Visible,'on');
323+
324+
%-------------------------------------------------------------------------%
325+
326+
%-contour showscale-%
327+
obj.data{contourIndex}.showscale = false;
328+
329+
%-------------------------------------------------------------------------%
330+
331+
%-contour reverse scale-%
332+
obj.data{contourIndex}.reversescale = false;
333+
334+
%-------------------------------------------------------------------------%
335+
277336
%-contour showlegend-%
278337

279338
leg = get(contour_data.Annotation);

0 commit comments

Comments
 (0)