Skip to content

Rendering issues with bar3 #232

Closed
Closed

Description

@xarico10

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

Activity

  1. self-assigned this
    on Aug 18, 2021
  2. removed their assignment
    on Aug 29, 2021
  3. nouman-tariq commented on Aug 29, 2021

    @nouman-tariq
    Contributor

    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)

  4. gilbertogalvis commented on Sep 10, 2021

    @gilbertogalvis
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions