Two Histograms on the same graph with a curved line

17 views (last 30 days)
Hello, I'm not sure where to to start with this problem so I'm asking the quesiton first for recommendations on where to start.
Essentially..
I have three graphs in one. there will be a line graph i can plot using the plot(x) function. However Underneath each of the points in the line graph i need to plot two histograms (one on top of the other). Essentially, if a point on the line graph is x=1, y=100, then the two histograms visualize the components to make y = 100.
e.g. Line Graph Point (1,100), Histogram 1 Point (1, 75), Histogram 2 Point (1, 25). Alternatively, Line Graph Point (1,100), Histogram 1 Point (1, -25), Histogram 2 Point (1, 125).
Either way the ylinegraph = yhistogram1 + yhistogram2 , and xlingegraph = xhistogram1 = xhistogram2.
I have approximately 500-100 points to plot per graph im doing.
Any suggestions on where to start would be greatly appreciated.
- Kyle

Accepted Answer

Star Strider
Star Strider on 29 Jan 2015
You don’t provide enough information or code to respond specifically, so I’ll provide an example:
Data = randi(25, 10,2); % Create Data For ‘bar’ Plot
Line = [0:0.5:5].^2; % Create Line Plot Data
figure(1)
bar(Data, 'Grouped') % Plot Histogram Using ‘bar’
hold on
plot([0:10], Line, 'LineWidth',1.5) % Plot Line
hold off
  2 Comments
Kyle
Kyle on 29 Jan 2015
Yes I'm sorry, I know I'm being very vague. Thank you, I was just looking for a starting point. That is actually much simpler than I anticipated and actually almost exactly what i'm looking for.
It's all correct, except I'm looking to overlap the Histograms on top of each other.
Star Strider
Star Strider on 29 Jan 2015
My pleasure.
To plot the histograms on top of each other, consider using the 'Stacked' option instead of 'Grouped':
bar(Data, 'Stacked') % Plot Histogram Using ‘bar’
See the documentation for bar for more details.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!