How can I add bar graphs to ribbon plots?

1 view (last 30 days)
Hello all,
I have a ribbon plot with the ribbons extending along a time axis. At the end of the time axis, I would like to have a bar graph: one bar for each ribbon, that shows the average height of the ribbon over time.
If I use hold on, the bars always go on the wrong axis (they go parallel to the ribbons, but I would like them in the other plane). I have tried plotting each in a subplot in specific positions and then rotating the whole plot (I would like view([37.5,30])), using linkplot, and I have tried with both bar and bar3 but nothing has worked so far.
Can anyone help? Thank you so much!

Accepted Answer

Star Strider
Star Strider on 16 Jun 2014
This seems to do what you want. Experiment with it until you get the result you want with your data.
Example:
x = linspace(0, 170, 200); % CREATE DATA
for k1 = 1:10
R(k1,:) = exp(-k1*0.0001*x) .* (k1*rand + sin(k1*pi*x/10)*rand)/10;
end
M = mean(R,2)
Mz = [M zeros(size(R,1),size(R,2)-1)]; % CREATE A MATRIX WITH MEANS AS FIRST COLUMN
figure(1)
ribbon(R')
hold on
bar3(Mz')
hold off
xlabel('X')
ylabel('Y')
produces:
  2 Comments
Justine
Justine on 16 Jun 2014
Thank you so much Star Strider! I don't know why I didn't try this before. WOOP!
Star Strider
Star Strider on 16 Jun 2014
My pleasure!
I experimented and then realised that I needed to make the argument to bar3 the same size as that to ribbon. Never tried to overplot with ribbon before, so I learned something!

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!