필터 지우기
필터 지우기

Overlaying Plots on Bar Graphs

조회 수: 2 (최근 30일)
Asdrubal
Asdrubal 2011년 6월 1일
I want to creat an overlaying a dot plot on a bar graph. It seems very simple but I am running into 2 problems (1) I can't get ride of tick markers on both right and left side. I want the right on the right and left on left (2) How can I label the bar with text (say ON, QC, BC) and the dot with values
My data and code
hmM = [0.8 0.6 0.2];
hm = [0.25 0.38 0.60];
figure (1)
bar(hmM, 'y')
h1 = gca;
h2 = axes('Position',get(h1,'Position'));
plot(hm,'*')
set(h2,'YAxisLocation','right', 'Color','none')
set(h2,'XLim',get(h1,'XLim'),'Layer','top')
  댓글 수: 3
Asdrubal
Asdrubal 2011년 6월 1일
Imagine 3 bars that I want to label with text; in the middle of these bars you have dots that I want to add the corresponding values. the scale for the bars would be on the leftand for the dots on the right
Asdrubal
Asdrubal 2011년 6월 6일
how to add colors to the bars; for instance make them yellow?
figure (1)
[AX, H1, H2] = plotyy(C,hm,C,hmM,@bar,@line);
set(get(AX(1),'Ylabel'), 'String','Data')
set(get(AX(2),'Ylabel'), 'String','Model')
set(H1,'Color','y')
set(H2,'LineStyle','*')

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 6월 1일
With regards to the ticks: what you should probably use is plotyy()
To label a dot with a value, you will need to text() the label at the appropriate position.
  댓글 수: 3
Asdrubal
Asdrubal 2011년 6월 6일
how to add colors to the bars; for instance make them yellow?
figure (1)
[AX, H1, H2] = plotyy(C,hm,C,hmM,@bar,@line);
set(get(AX(1),'Ylabel'), 'String','Data')
set(get(AX(2),'Ylabel'), 'String','Model')
set(H1,'Color','y')
set(H2,'LineStyle','*')
Walter Roberson
Walter Roberson 2011년 6월 6일
The color of the bars is in groups and is not trivial to change. Normally all of the bars for one particular data set (column of Y) are drawn as part of one single patch() object and only have a single color. The first bar of the first group, the first bar of the second group, the first bar of the third group, and so on -- all drawn with a single patch() object. The groupings of bars around an individual Y are *not* drawn as one group.
Changing the bars individually (instead of changing all bars belonging to a single data set) requires going in to the patch() object and manipulating the CData property to present different colors at different locations.
Changing the color associated with a single data set as a whole is not too bad, but does require going underneath the hggroup handle that is returned by bar() to get the patch() that is the appropriate child, and setting the FaceColor property of that patch (and probably the EdgeColor property too.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by