필터 지우기
필터 지우기

How to get a bar plot with unequal bin intervals?

조회 수: 2 (최근 30일)
Sim
Sim 2024년 3월 1일
댓글: Voss 2024년 3월 1일
How can I show the following bars (bar_heights) with unequal bin intervals (bin_edges)?
bin_edges = [0 5;
5 20;
20 100];
bar_heights = [20;10;30];
bar(bar_heights)
Basically, I would like to see the bar with height 20 starting at xtick 0 and ending at xtick 5, then the bar with height 10 starting at xtick 5 and ending at xtick 20, and the bar with height 30 from xtick 20 to xtick 100.
  댓글 수: 1
Sim
Sim 2024년 3월 1일
Maybe a way, but I am not able to show the last edge of the last bin, i.e. 100:
bin_edges = [0 5 20];
bar_heights = [20 10 30];
bar(bin_edges,bar_heights','histc')

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

채택된 답변

Voss
Voss 2024년 3월 1일
편집: Voss 2024년 3월 1일
bin_edges = [0 5 20 100]; % include the last edge (100)
bar_heights = [20 10 30];
bar(bin_edges,[bar_heights(:); 0],'histc') % append a 0 for plotting the last bin
xlim(bin_edges([1 end])) % set xlim to avoid showing the last (0-height) bin
  댓글 수: 2
Sim
Sim 2024년 3월 1일
thanks a lot @Voss!
Voss
Voss 2024년 3월 1일
You're welcome!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by