Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- my_bar3_org.m
- +++ my_bar3_new.m
- @@ -1,4 +1,4 @@
- -function pp = my_bar3(M, width)
- +function pp = my_bar3(M, width, C)
- % MY_BAR3 3D bar graph.
- %
- % M - 2D matrix
- @@ -33,6 +33,25 @@
- v = bsxfun(@plus, v, permute(offset,[3 2 1]));
- v = reshape(permute(v,[2 1 3]), 3,[]).';
- + % parse color argument
- + if nargin<3 || isempty(C)
- + % default solid color for all bars
- + color_args = {'FaceColor',[0.75 0.85 0.95]};
- + elseif ismatrix(C) && isequal(size(C),size(M))
- + % gradient colors, specified using indexed color mapping
- + fvcd = v(:,3) .* kron(C(:), ones(8,1));
- + color_args = {'FaceVertexCData',fvcd, 'FaceColor','interp'};
- + elseif ismatrix(C) && isequal(size(C),[numel(M) 3])
- + % matrix of flat true-colors, one per bar
- + fvcd = kron(C, ones(6,1));
- + color_args = {'FaceVertexCData',fvcd, 'FaceColor','flat'};
- + elseif (isvector(C) && numel(C)==3) || ischar(C)
- + % user-supplied solid color (accepts [0.1 0.1 0.1] or 'red')
- + color_args = {'FaceColor',C};
- + else
- + error('could not parse paramter C');
- + end
- +
- % adjust bar heights to be equal to matrix values
- v(:,3) = v(:,3) .* kron(M(:), ones(8,1));
- @@ -56,7 +75,7 @@
- % draw patch specified by faces/vertices
- % (we use a solid color for all faces)
- p = patch('Faces',f, 'Vertices',v, ...
- - 'FaceColor',[0.75 0.85 0.95], 'EdgeColor','k', 'Parent',hax);
- + 'EdgeColor','k', 'Parent',hax, color_args{:});
- view(hax,3); grid(hax,'on');
- set(hax, 'XTick',1:nx, 'YTick',1:ny, 'Box','off', 'YDir','reverse', ...
- 'PlotBoxAspectRatio',[1 1 (sqrt(5)-1)/2]) % 1/GR (GR: golden ratio)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement