Skip to content

Fix heatmap issues used in ssim baselines matlab code examples data distribution plots heatmap #354

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
20 changes: 18 additions & 2 deletions plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
obj.PlotOptions.TreatAs = '_';
obj.PlotOptions.Image3D = false;
obj.PlotOptions.ContourProjection = false;
obj.PlotOptions.AxisEqual = false;
obj.PlotOptions.AspectRatio = [];
obj.PlotOptions.CameraEye = [];
obj.PlotOptions.is_headmap_axis = false;

% offline options
obj.PlotOptions.Offline = true;
Expand Down Expand Up @@ -205,6 +209,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 +293,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 @@ -671,9 +685,10 @@ function validate(obj)
% update annotations
for n = 1:obj.State.Figure.NumTexts
try
if ~strcmpi(obj.State.Plot(dataIndex).Class, 'heatmap')
if ~obj.PlotOptions.is_headmap_axis
updateAnnotation(obj,n);
else
updateHeatmapAnnotation(obj,n);
obj.PlotOptions.CleanFeedTitle = false;
end
catch
Expand Down Expand Up @@ -983,7 +998,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
51 changes: 43 additions & 8 deletions plotly/plotlyfig_aux/core/updateAxis.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,64 @@

%-STANDARDIZE UNITS-%
axisunits = get(obj.State.Axis(axIndex).Handle,'Units');
fontunits = get(obj.State.Axis(axIndex).Handle,'FontUnits');
set(obj.State.Axis(axIndex).Handle,'Units','normalized');
set(obj.State.Axis(axIndex).Handle,'FontUnits','points');
set(obj.State.Axis(axIndex).Handle,'Units','normalized')

try
fontunits = get(obj.State.Axis(axIndex).Handle,'FontUnits');
set(obj.State.Axis(axIndex).Handle,'FontUnits','points')
catch
% TODO
end

%-AXIS DATA STRUCTURE-%
axis_data = get(obj.State.Axis(axIndex).Handle);

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

%-check if headmap axis-%
is_headmap_axis = isfield(axis_data, 'XDisplayData');
obj.PlotOptions.is_headmap_axis = is_headmap_axis;

%-xaxis-%
xaxis = extractAxisData(obj,axis_data,'X');
if ~is_headmap_axis
xaxis = extractAxisData(obj,axis_data,'X');
else
xaxis = extractHeatmapAxisData(obj,axis_data,'X');
end

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

%-yaxis-%
yaxis = extractAxisData(obj,axis_data,'Y');
if ~is_headmap_axis
yaxis = extractAxisData(obj,axis_data,'Y');
else
yaxis = extractHeatmapAxisData(obj,axis_data,'Y');
end

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

%-getting and setting postion data-%

xo = axis_data.Position(1);
yo = axis_data.Position(2);
w = axis_data.Position(3);
h = axis_data.Position(4);

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

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

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

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

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

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

Expand Down Expand Up @@ -120,6 +152,9 @@

%-REVERT UNITS-%
set(obj.State.Axis(axIndex).Handle,'Units',axisunits);
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontunits);

try
set(obj.State.Axis(axIndex).Handle,'FontUnits',fontunits);
catch
% TODO
end
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
101 changes: 101 additions & 0 deletions plotly/plotlyfig_aux/core/updateHeatmapAnnotation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
function obj = updateHeatmapAnnotation(obj,anIndex)

%-------X/YLABEL FIELDS--------%
% title...[DONE]
% titlefont.size...[DONE]
% titlefont.family...[DONE]
% titlefont.color...[DONE]

%------ANNOTATION FIELDS-------%

% x: ...[DONE]
% y: ...[DONE]
% xref: ...[DONE]
% yref: ...[DONE]
% text: ...[DONE]
% showarrow: ...[HANDLED BY CALL TO ANNOTATION];
% font: ...[DONE]
% xanchor: ...[DONE]
% yanchor: ...[DONE]
% align: ...[DONE]
% arrowhead: ...[HANDLED BY CALL FROM ANNOTATION];
% arrowsize: ...[HANDLED BY CALL FROM ANNOTATION];
% arrowwidth: ...[HANDLED BY CALL FROM ANNOTATION];
% arrowcolor: ...[HANDLED BY CALL FROM ANNOTATION];
% ax: ...[HANDLED BY CALL FROM ANNOTATION];
% ay: ...[HANDLED BY CALL FROM ANNOTATION];
% textangle: ...[DONE]
% bordercolor: ...[DONE]
% borderwidth: ...[DONE]
% borderpad: ...[DONE]
% bgcolor: ...[DONE]
% opacity: ...[NOT SUPPORTED IN MATLAB]


%-AXIS INDEX-%
axIndex = obj.getAxisIndex(obj.State.Text(anIndex).AssociatedAxis);

%-CHECK FOR MULTIPLE AXES-%
[xsource, ysource] = findSourceAxis(obj,axIndex);
eval(['xaxis = obj.layout.xaxis' num2str(xsource) ';']);
eval(['yaxis = obj.layout.yaxis' num2str(ysource) ';']);

%-get heatmap title name-%
title_name = obj.State.Text(anIndex).Handle;

%-show arrow-%
obj.layout.annotations{anIndex}.showarrow = false;

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

%-anchor title to paper-%
if obj.State.Text(anIndex).Title
%-xref-%
obj.layout.annotations{anIndex}.xref = 'paper';
%-yref-%
obj.layout.annotations{anIndex}.yref = 'paper';
else
%-xref-%
obj.layout.annotations{anIndex}.xref = ['x' num2str(xsource)];
%-yref-%
obj.layout.annotations{anIndex}.yref = ['y' num2str(ysource)];
end

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

%-xanchor-%
obj.layout.annotations{anIndex}.xanchor = 'middle';

%-align-%
obj.layout.annotations{anIndex}.align = 'middle';

%-xanchor-%
obj.layout.annotations{anIndex}.yanchor = 'top';


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

%-text-%
obj.layout.annotations{anIndex}.text = title_name;

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

if obj.State.Text(anIndex).Title

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

%-x position-%
obj.layout.annotations{anIndex}.x = mean(xaxis.domain);
%-y position-%
% obj.layout.annotations{anIndex}.y = (yaxis.domain(2) + obj.PlotlyDefaults.TitleHeight);
obj.layout.annotations{anIndex}.y = (yaxis.domain(2) + 0.04);
else
%-x position-%
obj.layout.annotations{anIndex}.x = text_data.Position(1);
%-y position-%
obj.layout.annotations{anIndex}.y = text_data.Position(2);
end

end
Loading