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 Center および File Exchange3-D Scene Control についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by