Advertisement
Guest User

my_bar3_diff.patch

a guest
Jul 4th, 2014
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.71 KB | None | 0 0
  1. --- my_bar3_org.m
  2. +++ my_bar3_new.m
  3. @@ -1,4 +1,4 @@
  4. -function pp = my_bar3(M, width)
  5. +function pp = my_bar3(M, width, C)
  6.      % MY_BAR3  3D bar graph.
  7.      %
  8.      % M     - 2D matrix
  9. @@ -33,6 +33,25 @@
  10.      v = bsxfun(@plus, v, permute(offset,[3 2 1]));
  11.      v = reshape(permute(v,[2 1 3]), 3,[]).';
  12.  
  13. +    % parse color argument
  14. +    if nargin<3 || isempty(C)
  15. +        % default solid color for all bars
  16. +        color_args = {'FaceColor',[0.75 0.85 0.95]};
  17. +    elseif ismatrix(C) && isequal(size(C),size(M))
  18. +        % gradient colors, specified using indexed color mapping
  19. +        fvcd = v(:,3) .* kron(C(:), ones(8,1));
  20. +        color_args = {'FaceVertexCData',fvcd, 'FaceColor','interp'};
  21. +    elseif ismatrix(C) && isequal(size(C),[numel(M) 3])
  22. +        % matrix of flat true-colors, one per bar
  23. +        fvcd = kron(C, ones(6,1));
  24. +        color_args = {'FaceVertexCData',fvcd, 'FaceColor','flat'};
  25. +    elseif (isvector(C) && numel(C)==3) || ischar(C)
  26. +        % user-supplied solid color (accepts [0.1 0.1 0.1] or 'red')
  27. +        color_args = {'FaceColor',C};
  28. +    else
  29. +        error('could not parse paramter C');
  30. +    end
  31. +
  32.      % adjust bar heights to be equal to matrix values
  33.      v(:,3) = v(:,3) .* kron(M(:), ones(8,1));
  34.  
  35. @@ -56,7 +75,7 @@
  36.      % draw patch specified by faces/vertices
  37.      % (we use a solid color for all faces)
  38.      p = patch('Faces',f, 'Vertices',v, ...
  39. -        'FaceColor',[0.75 0.85 0.95], 'EdgeColor','k', 'Parent',hax);
  40. +        'EdgeColor','k', 'Parent',hax, color_args{:});
  41.      view(hax,3); grid(hax,'on');
  42.      set(hax, 'XTick',1:nx, 'YTick',1:ny, 'Box','off', 'YDir','reverse', ...
  43.          'PlotBoxAspectRatio',[1 1 (sqrt(5)-1)/2]) % 1/GR (GR: golden ratio)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement