Skip to content

Commit 00077ff

Browse files
Merge pull request #353 from plotly/fix_contour_functions_for_ssim_baselines_matlab_contour-plots
Fix contour functions for ssim baselines matlab contour plots
2 parents 6dc5868 + c617eae commit 00077ff

File tree

7 files changed

+357
-221
lines changed

7 files changed

+357
-221
lines changed

Diff for: plotly/plotlyfig.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
for d = 1:length(obj.data)
293293
if ( ...
294294
strcmpi(obj.data{d}.type, 'scatter') || ...
295+
strcmpi(obj.data{d}.type, 'contour') || ...
295296
strcmpi(obj.data{d}.type, 'bar') ...
296297
)
297298
return
@@ -1001,7 +1002,8 @@ function delete(obj)
10011002
|| strcmpi(fieldname,'mesh3d') || strcmpi(fieldname,'bar') ...
10021003
|| strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ...
10031004
|| strcmpi(fieldname,'scene') || strcmpi(fieldname,'layout') ...
1004-
|| strcmpi(fieldname,'heatmap') ...
1005+
|| strcmpi(fieldname,'heatmap') || strcmpi(fieldname,'xaxis') ...
1006+
|| strcmpi(fieldname,'yaxis') ...
10051007
)
10061008
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
10071009
end

Diff for: plotly/plotlyfig_aux/core/updateData.m

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
updatePColor(obj, dataIndex);
1414
elseif strcmpi(obj.PlotOptions.TreatAs, 'polarplot')
1515
updatePolarplot(obj, dataIndex);
16+
elseif strcmpi(obj.PlotOptions.TreatAs, 'contour3')
17+
updateContour3(obj, dataIndex);
1618
end
1719

1820
%-update plot based on plot call class-%
@@ -148,6 +150,7 @@
148150
if strcmpi(xaxis.type, 'category') && ...
149151
~strcmp(obj.data{dataIndex}.type,'box')
150152
obj.data{dataIndex}.x = get(obj.State.Plot(dataIndex).AssociatedAxis,'XTickLabel');
153+
eval(['obj.layout.xaxis' num2str(xsource) '.autotick=true;']);
151154
end
152155

153156
% check for yaxis dates
@@ -159,6 +162,7 @@
159162
if strcmpi(yaxis.type, 'category') && ...
160163
~strcmp(obj.data{dataIndex}.type,'box')
161164
obj.data{dataIndex}.y = get(obj.State.Plot(dataIndex).AssociatedAxis,'YTickLabel');
165+
eval(['obj.layout.yaxis' num2str(xsource) '.autotick=true;']);
162166
end
163167
catch
164168
% TODO to the future

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

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
function obj = updateContour3(obj,contourIndex)
2+
3+
4+
%-FIGURE DATA STRUCTURE-%
5+
figure_data = get(obj.State.Figure.Handle);
6+
7+
%-AXIS INDEX-%
8+
axIndex = obj.getAxisIndex(obj.State.Plot(contourIndex).AssociatedAxis);
9+
10+
%-AXIS DATA STRUCTURE-%
11+
axis_data = get(obj.State.Plot(contourIndex).AssociatedAxis);
12+
13+
%-PLOT DATA STRUCTURE- %
14+
contour_data = get(obj.State.Plot(contourIndex).Handle);
15+
16+
%-CHECK FOR MULTIPLE AXES-%
17+
[xsource, ysource] = findSourceAxis(obj,axIndex);
18+
19+
%-AXIS DATA-%
20+
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
21+
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);
22+
23+
%-------------------------------------------------------------------------%
24+
25+
%-contour xaxis-%
26+
obj.data{contourIndex}.xaxis = ['x' num2str(xsource)];
27+
28+
%-------------------------------------------------------------------------%
29+
30+
%-contour yaxis-%
31+
obj.data{contourIndex}.yaxis = ['y' num2str(ysource)];
32+
33+
%-------------------------------------------------------------------------%
34+
35+
%-contour name-%
36+
obj.data{contourIndex}.name = contour_data.DisplayName;
37+
38+
%-------------------------------------------------------------------------%
39+
40+
%-setting the plot-%
41+
xdata = contour_data.XData;
42+
ydata = contour_data.YData;
43+
zdata = contour_data.ZData;
44+
45+
%---------------------------------------------------------------------%
46+
47+
%-contour type-%
48+
obj.data{contourIndex}.type = 'surface';
49+
50+
%---------------------------------------------------------------------%
51+
52+
%-contour x and y data
53+
if isvector(xdata)
54+
[xdata, ydata] = meshgrid(xdata, ydata);
55+
end
56+
obj.data{contourIndex}.x = xdata;
57+
obj.data{contourIndex}.y = ydata;
58+
59+
%---------------------------------------------------------------------%
60+
61+
%-contour z data-%
62+
obj.data{contourIndex}.z = zdata;
63+
64+
%---------------------------------------------------------------------%
65+
66+
%-setting for contour lines z-direction-%
67+
if length(contour_data.LevelList) > 1
68+
zstart = contour_data.TextList(1);
69+
zend = contour_data.TextList(end);
70+
zsize = mean(diff(contour_data.TextList));
71+
else
72+
zstart = contour_data.TextList(1) - 1e-3;
73+
zend = contour_data.TextList(end) + 1e-3;
74+
zsize = 2e-3;
75+
end
76+
77+
obj.data{contourIndex}.contours.z.start = zstart;
78+
obj.data{contourIndex}.contours.z.end = zend;
79+
obj.data{contourIndex}.contours.z.size = zsize;
80+
obj.data{contourIndex}.contours.z.show = true;
81+
obj.data{contourIndex}.contours.z.usecolormap = true;
82+
obj.data{contourIndex}.contours.z.width = 2*contour_data.LineWidth;
83+
obj.data{contourIndex}.hidesurface = true;
84+
85+
%---------------------------------------------------------------------%
86+
87+
%-colorscale-%
88+
colormap = figure_data.Colormap;
89+
90+
for c = 1:size((colormap),1)
91+
col = 255*(colormap(c,:));
92+
obj.data{contourIndex}.colorscale{c} = {(c-1)/(size(colormap,1)-1), ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']};
93+
end
94+
95+
%---------------------------------------------------------------------%
96+
97+
%-aspect ratio-%
98+
ar = obj.PlotOptions.AspectRatio;
99+
100+
if ~isempty(ar)
101+
if ischar(ar)
102+
obj.layout.scene.aspectmode = ar;
103+
elseif isvector(ar) && length(ar) == 3
104+
xar = ar(1);
105+
yar = ar(2);
106+
zar = ar(3);
107+
end
108+
else
109+
110+
%-define as default-%
111+
xar = max(xdata(:));
112+
yar = max(ydata(:));
113+
zar = 0.7*max([xar, yar]);
114+
end
115+
116+
obj.layout.scene.aspectratio.x = xar;
117+
obj.layout.scene.aspectratio.y = yar;
118+
obj.layout.scene.aspectratio.z = zar;
119+
120+
%---------------------------------------------------------------------%
121+
122+
%-camera eye-%
123+
ey = obj.PlotOptions.CameraEye;
124+
125+
if ~isempty(ey)
126+
if isvector(ey) && length(ey) == 3
127+
obj.layout.scene.camera.eye.x = ey(1);
128+
obj.layout.scene.camera.eye.y = ey(2);
129+
obj.layout.scene.camera.eye.z = ey(3);
130+
end
131+
else
132+
133+
%-define as default-%
134+
xey = - xar; if xey>0 xfac = -0.2; else xfac = 0.2; end
135+
yey = - yar; if yey>0 yfac = -0.2; else yfac = 0.2; end
136+
if zar>0 zfac = 0.2; else zfac = -0.2; end
137+
138+
obj.layout.scene.camera.eye.x = xey + xfac*xey;
139+
obj.layout.scene.camera.eye.y = yey + yfac*yey;
140+
obj.layout.scene.camera.eye.z = zar + zfac*zar;
141+
end
142+
143+
%---------------------------------------------------------------------%
144+
145+
%-zerolines hidded-%
146+
obj.layout.scene.xaxis.zeroline = false;
147+
obj.layout.scene.yaxis.zeroline = false;
148+
obj.layout.scene.zaxis.zeroline = false;
149+
150+
%-------------------------------------------------------------------------%
151+
152+
%-contour visible-%
153+
obj.data{contourIndex}.visible = strcmp(contour_data.Visible,'on');
154+
155+
%-------------------------------------------------------------------------%
156+
157+
%-contour showscale-%
158+
obj.data{contourIndex}.showscale = false;
159+
160+
%-------------------------------------------------------------------------%
161+
162+
%-contour reverse scale-%
163+
obj.data{contourIndex}.reversescale = false;
164+
165+
%-------------------------------------------------------------------------%
166+
167+
%-contour showlegend-%
168+
169+
leg = get(contour_data.Annotation);
170+
legInfo = get(leg.LegendInformation);
171+
172+
switch legInfo.IconDisplayStyle
173+
case 'on'
174+
showleg = true;
175+
case 'off'
176+
showleg = false;
177+
end
178+
179+
obj.data{contourIndex}.showlegend = showleg;
180+
181+
%-------------------------------------------------------------------------%
182+
183+
end

0 commit comments

Comments
 (0)