Create a sideways filled in bar plot

조회 수: 2 (최근 30일)
William Garrett
William Garrett 2020년 5월 4일
답변: Star Strider 2020년 5월 4일
I want to create a figure that looks alike the attached, where I have a bar and when the value is 1, it is filled in blue, and when the value is 0 it has no colour.
The x axis must be datetime values and the bars must have filled colour, i.e. they cannot be outlines
Is this possible to do on MATLAB?

답변 (2개)

David Hill
David Hill 2020년 5월 4일
Yes, see bar() function
  댓글 수: 2
William Garrett
William Garrett 2020년 5월 4일
The bar function creates a barchart. What I need is a sideways bar with some parts filled in and other parts not, alike the figure. Unless I am mistaking your direction?
David Hill
David Hill 2020년 5월 4일
Look at barh() function and see if you can figure it out.

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


Star Strider
Star Strider 2020년 5월 4일
It would help to have an example of your data.
That aside, the sort of plot you want to do is straightforward.
Try this:
v = sort(rand(1,20)); % Create Vecttor Of Independent Variable Values
figure
yv = [0 0 1 1];
hold on
for k = 1:2:numel(v)-1
patch([v(k:k+1) fliplr(v(k:k+1))], yv, 'b')
end
hold off
It would likely be relatively straightforward to adapt this to a datetime vector.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by