Skip to content

fix legend issues with pie3 code-examples in ssim_baselines/matlab/code-examples/data-distribution-plots/pie3/ #362

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
4 changes: 3 additions & 1 deletion plotly/plotlyfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,9 @@ function validate(obj)

% update legends
for n = 1:obj.State.Figure.NumLegends
updateLegend(obj,n);
if ~strcmpi(obj.PlotOptions.TreatAs, 'pie3')
updateLegend(obj,n);
end
end

% update colorbars
Expand Down
244 changes: 127 additions & 117 deletions plotly/plotlyfig_aux/handlegraphics/updatePie3.m
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
function updatePie3(obj,plotIndex)

%-update according to patch or surface-%
if strcmpi(obj.State.Plot(plotIndex).Class, 'patch')
updatePatchPie3(obj, plotIndex);
else
updateSurfacePie3(obj, plotIndex);
end

%-hide axis-x-%
obj.PlotOptions.scene.xaxis.title = '';
obj.PlotOptions.scene.xaxis.autotick = false;
obj.PlotOptions.scene.xaxis.zeroline = false;
obj.PlotOptions.scene.xaxis.showline = false;
obj.PlotOptions.scene.xaxis.showticklabels = false;
obj.PlotOptions.scene.xaxis.showgrid = false;

%-hide axis-y-%
obj.PlotOptions.scene.yaxis.title = '';
obj.PlotOptions.scene.yaxis.autotick = false;
obj.PlotOptions.scene.yaxis.zeroline = false;
obj.PlotOptions.scene.yaxis.showline = false;
obj.PlotOptions.scene.yaxis.showticklabels = false;
obj.PlotOptions.scene.yaxis.showgrid = false;

%-hide axis-z-%
obj.PlotOptions.scene.zaxis.title = '';
obj.PlotOptions.scene.zaxis.autotick = false;
obj.PlotOptions.scene.zaxis.zeroline = false;
obj.PlotOptions.scene.zaxis.showline = false;
obj.PlotOptions.scene.zaxis.showticklabels = false;
obj.PlotOptions.scene.zaxis.showgrid = false;

%-put text-%
obj.data{plotIndex}.hoverinfo = 'text';
obj.data{plotIndex}.hovertext = obj.PlotOptions.perc;
%-update according to patch or surface-%
if strcmpi(obj.State.Plot(plotIndex).Class, 'patch')
updatePatchPie3(obj, plotIndex);
else
updateSurfacePie3(obj, plotIndex);
end

obj.layout = setfield(obj.layout,['scene' obj.PlotOptions.scene_anchor(end)], obj.PlotOptions.scene);
obj.data{plotIndex}.scene = obj.PlotOptions.scene_anchor;
%-hide axis-x-%
obj.PlotOptions.scene.xaxis.title = '';
obj.PlotOptions.scene.xaxis.autotick = false;
obj.PlotOptions.scene.xaxis.zeroline = false;
obj.PlotOptions.scene.xaxis.showline = false;
obj.PlotOptions.scene.xaxis.showticklabels = false;
obj.PlotOptions.scene.xaxis.showgrid = false;

%-hide axis-y-%
obj.PlotOptions.scene.yaxis.title = '';
obj.PlotOptions.scene.yaxis.autotick = false;
obj.PlotOptions.scene.yaxis.zeroline = false;
obj.PlotOptions.scene.yaxis.showline = false;
obj.PlotOptions.scene.yaxis.showticklabels = false;
obj.PlotOptions.scene.yaxis.showgrid = false;

%-hide axis-z-%
obj.PlotOptions.scene.zaxis.title = '';
obj.PlotOptions.scene.zaxis.autotick = false;
obj.PlotOptions.scene.zaxis.zeroline = false;
obj.PlotOptions.scene.zaxis.showline = false;
obj.PlotOptions.scene.zaxis.showticklabels = false;
obj.PlotOptions.scene.zaxis.showgrid = false;

%-put text-%
obj.data{plotIndex}.hoverinfo = 'text';
obj.data{plotIndex}.hovertext = obj.PlotOptions.perc;

%-update scene-%
obj.layout = setfield(obj.layout,['scene' obj.PlotOptions.scene_anchor(end)], obj.PlotOptions.scene);
obj.data{plotIndex}.scene = obj.PlotOptions.scene_anchor;
obj.data{plotIndex}.legendgroup = obj.PlotOptions.scene_anchor;

%-update legend-%
obj.layout.legend.tracegroupgap = 20;
obj.layout.legend.traceorder = 'grouped';
obj.layout.legend.bordercolor = 'rgb(200,200,200)';
obj.layout.legend.x = 0.8;
obj.layout.legend.y = 0.5;
obj.layout.legend.borderwidth = 0.5;

end

Expand All @@ -53,15 +63,15 @@ function updatePie3(obj,plotIndex)

%-get the percentage-%
if ~any(nonzeros(patch_data.ZData))
t1 = atan2(patch_data.YData(2), patch_data.XData(2));
t2 = atan2(patch_data.YData(end-1), patch_data.XData(end-1));
a = rad2deg(t2-t1);
if a < 0
a = a+360;
end
obj.PlotOptions.perc = sprintf('%d %%', round(100*a/360));
t1 = atan2(patch_data.YData(2), patch_data.XData(2));
t2 = atan2(patch_data.YData(end-1), patch_data.XData(end-1));

a = rad2deg(t2-t1);
if a < 0
a = a+360;
end

obj.PlotOptions.perc = sprintf('%d %%', round(100*a/360));
end

%-CHECK FOR MULTIPLE AXES-%
Expand All @@ -86,29 +96,29 @@ function updatePie3(obj,plotIndex)
%-patch x-%
xdata = patch_data.XData;
if isvector(xdata)
obj.data{patchIndex}.x = [xdata' xdata(1)];
obj.data{patchIndex}.x = [xdata' xdata(1)];
else
xtemp = reshape(xdata,[],1);
xnew = [];
for n = 1:size(xdata,2)
xnew = [xnew ; xdata(:,n) ; xdata(1,n); NaN];
end
obj.data{patchIndex}.x = xnew;
xtemp = reshape(xdata,[],1);
xnew = [];
for n = 1:size(xdata,2)
xnew = [xnew ; xdata(:,n) ; xdata(1,n); NaN];
end
obj.data{patchIndex}.x = xnew;
end

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

%-patch y-%
ydata = patch_data.YData;
if isvector(ydata)
obj.data{patchIndex}.y = [ydata' ydata(1)];
obj.data{patchIndex}.y = [ydata' ydata(1)];
else
ytemp = reshape(ydata,[],1);
ynew = [];
for n = 1:size(ydata,2)
ynew = [ynew ; ydata(:,n) ; ydata(1,n); NaN];
end
obj.data{patchIndex}.y = ynew;
ytemp = reshape(ydata,[],1);
ynew = [];
for n = 1:size(ydata,2)
ynew = [ynew ; ydata(:,n) ; ydata(1,n); NaN];
end
obj.data{patchIndex}.y = ynew;
end

%---------------------------------------------------------------------%
Expand All @@ -117,23 +127,23 @@ function updatePie3(obj,plotIndex)
zdata = patch_data.ZData;

if isvector(ydata)
obj.data{patchIndex}.z = [zdata' zdata(1)];
obj.data{patchIndex}.z = [zdata' zdata(1)];
else
ztemp = reshape(zdata,[],1);
znew = [];
for n = 1:size(zdata,2)
znew = [znew ; zdata(:,n) ; zdata(1,n); NaN];
end
obj.data{patchIndex}.z = znew;
ztemp = reshape(zdata,[],1);
znew = [];
for n = 1:size(zdata,2)
znew = [znew ; zdata(:,n) ; zdata(1,n); NaN];
end
obj.data{patchIndex}.z = znew;
end

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

%-patch name-%
if ~isempty(patch_data.DisplayName)
obj.data{patchIndex}.name = patch_data.DisplayName;
obj.data{patchIndex}.name = patch_data.DisplayName;
else
obj.data{patchIndex}.name = patch_data.DisplayName;
obj.data{patchIndex}.name = patch_data.DisplayName;
end

%---------------------------------------------------------------------%
Expand All @@ -144,17 +154,17 @@ function updatePie3(obj,plotIndex)
%---------------------------------------------------------------------%

%-patch fill-%
% obj.data{patchIndex}.fill = 'tozeroy';
% obj.data{patchIndex}.fill = 'tozeroy';

%-PATCH MODE-%
if ~strcmpi('none', patch_data.Marker) && ~strcmpi('none', patch_data.LineStyle)
mode = 'lines+markers';
mode = 'lines+markers';
elseif ~strcmpi('none', patch_data.Marker)
mode = 'markers';
mode = 'markers';
elseif ~strcmpi('none', patch_data.LineStyle)
mode = 'lines';
mode = 'lines';
else
mode = 'none';
mode = 'none';
end

obj.data{patchIndex}.mode = mode;
Expand All @@ -173,21 +183,19 @@ function updatePie3(obj,plotIndex)

%-patch fillcolor-%
fill = extractPatchFace(patch_data);
obj.data{patchIndex}.surfacecolor = fill.color;

if strcmp(obj.data{patchIndex}.type,'scatter')
obj.data{patchIndex}.fillcolor = fill.color;
else
obj.data{patchIndex}.surfacecolor = fill.color;
if zdata(1) == 0
obj.data{patchIndex}.line.width = 3;
obj.data{patchIndex}.line.color = fill.color;
end

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

%-surfaceaxis-%
if strcmp(obj.data{patchIndex}.type,'scatter3d')
minstd = min([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)]);
ind = find([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)] == minstd)-1;
obj.data{patchIndex}.surfaceaxis = ind;
end
minstd = min([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)]);
ind = find([std(patch_data.XData) std(patch_data.YData) std(patch_data.ZData)] == minstd)-1;
obj.data{patchIndex}.surfaceaxis = ind;

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

Expand All @@ -196,10 +204,10 @@ function updatePie3(obj,plotIndex)
legInfo = get(leg.LegendInformation);

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

obj.data{patchIndex}.showlegend = showleg;
Expand Down Expand Up @@ -253,8 +261,8 @@ function updatePie3(obj,plotIndex)
len = length(cmap)-1;

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

obj.data{surfaceIndex}.surfacecolor = 255*(image_data.CData-1) / (obj.PlotOptions.nbars{xsource} - 1);
Expand All @@ -271,19 +279,19 @@ function updatePie3(obj,plotIndex)
ar = obj.PlotOptions.AspectRatio;

if ~isempty(ar)
if ischar(ar)
scene.aspectmode = ar;
elseif isvector(ar) && length(ar) == 3
xar = ar(1);
yar = ar(2);
zar = ar(3);
end
if ischar(ar)
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 = max([xar, yar]);
%-define as default-%
xar = max(xdata(:));
yar = max(ydata(:));
zar = max([xar, yar]);
end

fac1 = 0.75;
Expand All @@ -305,21 +313,21 @@ function updatePie3(obj,plotIndex)
ey = obj.PlotOptions.CameraEye;

if ~isempty(ey)
if isvector(ey) && length(ey) == 3
scene.camera.eye.x = ey(1);
scene.camera.eye.y = ey(2);
scene.camera.eye.z = ey(3);
end
if isvector(ey) && length(ey) == 3
scene.camera.eye.x = ey(1);
scene.camera.eye.y = ey(2);
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
scene.camera.eye.x = xey + xfac*xey;
scene.camera.eye.y = yey + yfac*yey;
scene.camera.eye.z = zar + zfac*zar;
%-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

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

%-------------------------------------------------------------------------%
Expand All @@ -331,6 +339,7 @@ function updatePie3(obj,plotIndex)

%-surface name-%
obj.data{surfaceIndex}.name = image_data.DisplayName;
obj.data{surfaceIndex-1}.name = image_data.DisplayName;

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

Expand All @@ -348,13 +357,14 @@ function updatePie3(obj,plotIndex)
legInfo = get(leg.LegendInformation);

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

obj.data{surfaceIndex}.showlegend = showleg;
obj.data{surfaceIndex-1}.showlegend = showleg;
obj.data{surfaceIndex}.showlegend = false;

%-------------------------------------------------------------------------%
end
Expand Down