Skip to content

Rendering issues with bar3 #232

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

Closed
xarico10 opened this issue Jul 30, 2021 · 2 comments
Closed

Rendering issues with bar3 #232

xarico10 opened this issue Jul 30, 2021 · 2 comments

Comments

@xarico10
Copy link
Contributor

xarico10 commented Jul 30, 2021

There are rendering issues when using bar3() to create 3-D bar charts.

load count.dat
Z = count(1:10,:);
figure
bar3(Z,'r')
title('Detached Style')

fig2plotly(gcf, 'offline', false)

The bars aren't rendering correctly and the coloring seems to follow a heat map format when it should be just red.

Expected and generated (https://chart-studio.plotly.com/~xarico10/595/detached-style/#/) plots:
Captura de Pantalla 2021-07-30 a la(s) 4 07 58 p  m

Captura de Pantalla 2021-07-30 a la(s) 4 00 47 p  m

Examples on using bar3() can be found on:
https://www.mathworks.com/help/matlab/ref/bar3.html#responsive_offcanvas

@nouman-tariq nouman-tariq self-assigned this Aug 18, 2021
@nouman-tariq nouman-tariq removed their assignment Aug 29, 2021
@nouman-tariq
Copy link
Contributor

nouman-tariq commented Aug 29, 2021

I was not able to completely solve this issue, but some of it

this code will resolve the color problem of the above issue with little modifications in the updateSurfaceplot.m file

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

bar3 = false;

try
    if (isfield(image_data, 'Tag') && strcmp(image_data.Tag, 'bar3'))
        bar3 = true;
    end
catch
    %TODO
end

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

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

%-image colorscale-%

cmap = figure_data.Colormap;
len = length(cmap)-1;

if bar3
    faceColor = image_data.FaceColor;
    if isnumeric(faceColor)
        color = 255*faceColor;
        for c = 1: length(cmap)
            obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(color(1)) ',' num2str(color(2)) ',' num2str(color(3)) ')'  ]  };
        end
    else
        switch faceColor
            case 'none'
                color = [255, 255, 255]; %TODO
                for c = 1: length(cmap)
                    obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(color(1)) ',' num2str(color(2)) ',' num2str(color(3)) ')'  ]  };
                end
            case 'flat'
                scalefactor = (surfaceIndex - figure_data.CurrentAxes.CLim(1))/diff(figure_data.CurrentAxes.CLim);
                color =  255*(cmap(1 + floor(scalefactor*(length(cmap)-1)),:));
                for c = 1: length(cmap)
                    obj.data{surfaceIndex}.colorscale{c} = { (c-1)/len , ['rgb(' num2str(color(1)) ',' num2str(color(2)) ',' num2str(color(3)) ')'  ]  };
                end
        end
    end
    
else
    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)) ')'  ]  };
    end
end

and this code will fix the bar positions in the same file-

%-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(x(:));
    yar = max(y(:));
    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
% 
% xey = figure_data.CurrentAxes.DataAspectRatio(1);
% yey = figure_data.CurrentAxes.DataAspectRatio(2);
% zey = figure_data.CurrentAxes.DataAspectRatio(3);
%---------------------------------------------------------------------%

(help taken from the other functions)

@gilbertogalvis
Copy link
Contributor

This issue was fixed y PR #373.

Attach results bellow (examples in https://github.com/plotly/ssim_baselines/tree/main/matlab/code-examples/discrete-data-plots/bar3)

Screen Shot 2021-09-10 at 11 56 38 AM

Screen Shot 2021-09-10 at 11 56 56 AM

Screen Shot 2021-09-10 at 11 57 14 AM

Screen Shot 2021-09-10 at 11 57 31 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants