Bar plot with a single bar across multiple x-axis values

조회 수: 1 (최근 30일)
PChoppala
PChoppala 2014년 9월 1일
댓글: Star Strider 2014년 9월 1일
I need to plot a single horizontal bar across multiple x-axis values, e.g.,
y=[2 1 3];
bar(1:6,y(1),'c', 2:5,y(2),'m', 6:10,y(3),'y');
I would like to see a single horizontal bar along x-axis: a) from 1 to 6 at a y-axis height of 2, b) from 2 to 5 at a y-axis height of 1, and c) from 6 to 10 at a y-axis height of 3. Could you please help me plot so?
Moreover, is there a possibility to [visually] distinguish the overlay bars (using colors or the like)? Because .. in the example provided above, the bar along x-axis 2 to 5 with height 1 units cannot be seen.

채택된 답변

Star Strider
Star Strider 2014년 9월 1일
This works:
y=[2 1 3];
figure(1)
patch([1 6 6 1], [0 0 2 2],'b')
hold on
patch([2 5 5 2],[0 0 1 1],'r')
patch([6 10 10 6],[0 0 3 3], 'g')
hold off
axis([1 10 0 5])
Make changes to the colours to your liking.
The plot:
  댓글 수: 4
PChoppala
PChoppala 2014년 9월 1일
Got it, thank you!
Star Strider
Star Strider 2014년 9월 1일
My pleasure!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by