Skip to content

Fix contour functions for ssim baselines matlab contour plots #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
obj.PlotOptions.TreatAs = '_';
obj.PlotOptions.Image3D = false;
obj.PlotOptions.ContourProjection = false;
obj.PlotOptions.AxisEqual = false;
obj.PlotOptions.AspectRatio = [];
obj.PlotOptions.CameraEye = [];

% offline options
obj.PlotOptions.Offline = true;
Expand Down Expand Up @@ -205,6 +208,15 @@
if(strcmpi(varargin{a},'TreatAs'))
obj.PlotOptions.TreatAs = varargin{a+1};
end
if(strcmpi(varargin{a},'AxisEqual'))
obj.PlotOptions.AxisEqual = varargin{a+1};
end
if(strcmpi(varargin{a},'AspectRatio'))
obj.PlotOptions.AspectRatio = varargin{a+1};
end
if(strcmpi(varargin{a},'CameraEye'))
obj.PlotOptions.CameraEye = varargin{a+1};
end
end
end

Expand Down Expand Up @@ -280,6 +292,7 @@
for d = 1:length(obj.data)
if ( ...
strcmpi(obj.data{d}.type, 'scatter') || ...
strcmpi(obj.data{d}.type, 'contour') || ...
strcmpi(obj.data{d}.type, 'bar') ...
)
return
Expand Down Expand Up @@ -670,8 +683,14 @@ function validate(obj)

% update annotations
for n = 1:obj.State.Figure.NumTexts
try
plotclass = obj.State.Plot(n).Class;
catch
plotclass = ' ';
end

try
if ~strcmpi(obj.State.Plot(dataIndex).Class, 'heatmap')
if ~strcmpi(plotclass, 'heatmap')
updateAnnotation(obj,n);
else
obj.PlotOptions.CleanFeedTitle = false;
Expand Down Expand Up @@ -983,7 +1002,8 @@ function delete(obj)
|| strcmpi(fieldname,'mesh3d') || strcmpi(fieldname,'bar') ...
|| strcmpi(fieldname,'scatterpolar') || strcmpi(fieldname,'barpolar') ...
|| strcmpi(fieldname,'scene') || strcmpi(fieldname,'layout') ...
|| strcmpi(fieldname,'heatmap') ...
|| strcmpi(fieldname,'heatmap') || strcmpi(fieldname,'xaxis') ...
|| strcmpi(fieldname,'yaxis') ...
)
fprintf(['\nWhoops! ' exception.message(1:end-1) ' in ' fieldname '\n\n']);
end
Expand Down
13 changes: 11 additions & 2 deletions plotly/plotlyfig_aux/core/updateAxis.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@

%-------------------------------------------------------------------------%

if obj.PlotOptions.AxisEqual
wh = min(axis_data.Position(3:4));
w = wh;
h = wh;
else
w = axis_data.Position(3);
h = axis_data.Position(4);
end

%-xaxis domain-%
xaxis.domain = min([axis_data.Position(1) axis_data.Position(1)+axis_data.Position(3)],1);
xaxis.domain = min([axis_data.Position(1) axis_data.Position(1) + w],1);

%-------------------------------------------------------------------------%

%-yaxis domain-%
yaxis.domain = min([axis_data.Position(2) axis_data.Position(2)+axis_data.Position(4)],1);
yaxis.domain = min([axis_data.Position(2) axis_data.Position(2) + h],1);

%-------------------------------------------------------------------------%

Expand Down
4 changes: 4 additions & 0 deletions plotly/plotlyfig_aux/core/updateData.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
updatePColor(obj, dataIndex);
elseif strcmpi(obj.PlotOptions.TreatAs, 'polarplot')
updatePolarplot(obj, dataIndex);
elseif strcmpi(obj.PlotOptions.TreatAs, 'contour3')
updateContour3(obj, dataIndex);
end

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

% check for yaxis dates
Expand All @@ -159,6 +162,7 @@
if strcmpi(yaxis.type, 'category') && ...
~strcmp(obj.data{dataIndex}.type,'box')
obj.data{dataIndex}.y = get(obj.State.Plot(dataIndex).AssociatedAxis,'YTickLabel');
eval(['obj.layout.yaxis' num2str(xsource) '.autotick=true;']);
end
catch
% TODO to the future
Expand Down
13 changes: 11 additions & 2 deletions plotly/plotlyfig_aux/core/updateFigure.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,22 @@

%-------------------------------------------------------------------------%

if obj.PlotOptions.AxisEqual
wh = min(figure_data.Position(3:4));
w = wh;
h = wh;
else
w = figure_data.Position(3);
h = figure_data.Position(4);
end

%-figure width-%
obj.layout.width = figure_data.Position(3)*obj.PlotlyDefaults.FigureIncreaseFactor;
obj.layout.width = w * obj.PlotlyDefaults.FigureIncreaseFactor;

%-------------------------------------------------------------------------%

%-figure height-%
obj.layout.height = figure_data.Position(4)*obj.PlotlyDefaults.FigureIncreaseFactor;
obj.layout.height = h * obj.PlotlyDefaults.FigureIncreaseFactor;

%-------------------------------------------------------------------------%

Expand Down
183 changes: 183 additions & 0 deletions plotly/plotlyfig_aux/handlegraphics/updateContour3.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
function obj = updateContour3(obj,contourIndex)


%-FIGURE DATA STRUCTURE-%
figure_data = get(obj.State.Figure.Handle);

%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Plot(contourIndex).AssociatedAxis);

%-AXIS DATA STRUCTURE-%
axis_data = get(obj.State.Plot(contourIndex).AssociatedAxis);

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

%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj,axIndex);

%-AXIS DATA-%
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);

%-------------------------------------------------------------------------%

%-contour xaxis-%
obj.data{contourIndex}.xaxis = ['x' num2str(xsource)];

%-------------------------------------------------------------------------%

%-contour yaxis-%
obj.data{contourIndex}.yaxis = ['y' num2str(ysource)];

%-------------------------------------------------------------------------%

%-contour name-%
obj.data{contourIndex}.name = contour_data.DisplayName;

%-------------------------------------------------------------------------%

%-setting the plot-%
xdata = contour_data.XData;
ydata = contour_data.YData;
zdata = contour_data.ZData;

%---------------------------------------------------------------------%

%-contour type-%
obj.data{contourIndex}.type = 'surface';

%---------------------------------------------------------------------%

%-contour x and y data
if isvector(xdata)
[xdata, ydata] = meshgrid(xdata, ydata);
end
obj.data{contourIndex}.x = xdata;
obj.data{contourIndex}.y = ydata;

%---------------------------------------------------------------------%

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

%---------------------------------------------------------------------%

%-setting for contour lines z-direction-%
if length(contour_data.LevelList) > 1
zstart = contour_data.TextList(1);
zend = contour_data.TextList(end);
zsize = mean(diff(contour_data.TextList));
else
zstart = contour_data.TextList(1) - 1e-3;
zend = contour_data.TextList(end) + 1e-3;
zsize = 2e-3;
end

obj.data{contourIndex}.contours.z.start = zstart;
obj.data{contourIndex}.contours.z.end = zend;
obj.data{contourIndex}.contours.z.size = zsize;
obj.data{contourIndex}.contours.z.show = true;
obj.data{contourIndex}.contours.z.usecolormap = true;
obj.data{contourIndex}.contours.z.width = 2*contour_data.LineWidth;
obj.data{contourIndex}.hidesurface = true;

%---------------------------------------------------------------------%

%-colorscale-%
colormap = figure_data.Colormap;

for c = 1:size((colormap),1)
col = 255*(colormap(c,:));
obj.data{contourIndex}.colorscale{c} = {(c-1)/(size(colormap,1)-1), ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')']};
end

%---------------------------------------------------------------------%

%-aspect ratio-%
ar = obj.PlotOptions.AspectRatio;

if ~isempty(ar)
if ischar(ar)
obj.layout.scene.aspectmode = ar;
elseif isvector(ar) && length(ar) == 3
xar = ar(1);
yar = ar(2);
zar = ar(3);
end
else

%-define as default-%
xar = max(xdata(:));
yar = max(ydata(:));
zar = 0.7*max([xar, yar]);
end

obj.layout.scene.aspectratio.x = xar;
obj.layout.scene.aspectratio.y = yar;
obj.layout.scene.aspectratio.z = zar;

%---------------------------------------------------------------------%

%-camera eye-%
ey = obj.PlotOptions.CameraEye;

if ~isempty(ey)
if isvector(ey) && length(ey) == 3
obj.layout.scene.camera.eye.x = ey(1);
obj.layout.scene.camera.eye.y = ey(2);
obj.layout.scene.camera.eye.z = ey(3);
end
else

%-define as default-%
xey = - xar; if xey>0 xfac = -0.2; else xfac = 0.2; end
yey = - yar; if yey>0 yfac = -0.2; else yfac = 0.2; end
if zar>0 zfac = 0.2; else zfac = -0.2; end

obj.layout.scene.camera.eye.x = xey + xfac*xey;
obj.layout.scene.camera.eye.y = yey + yfac*yey;
obj.layout.scene.camera.eye.z = zar + zfac*zar;
end

%---------------------------------------------------------------------%

%-zerolines hidded-%
obj.layout.scene.xaxis.zeroline = false;
obj.layout.scene.yaxis.zeroline = false;
obj.layout.scene.zaxis.zeroline = false;

%-------------------------------------------------------------------------%

%-contour visible-%
obj.data{contourIndex}.visible = strcmp(contour_data.Visible,'on');

%-------------------------------------------------------------------------%

%-contour showscale-%
obj.data{contourIndex}.showscale = false;

%-------------------------------------------------------------------------%

%-contour reverse scale-%
obj.data{contourIndex}.reversescale = false;

%-------------------------------------------------------------------------%

%-contour showlegend-%

leg = get(contour_data.Annotation);
legInfo = get(leg.LegendInformation);

switch legInfo.IconDisplayStyle
case 'on'
showleg = true;
case 'off'
showleg = false;
end

obj.data{contourIndex}.showlegend = showleg;

%-------------------------------------------------------------------------%

end
Loading