How can I set the histogram width

2 次查看(过去 30 天)
Minhee
Minhee 2023-11-27
评论: Minhee 2023-11-27
I want same distance between each bars. Now the distance between 1 and 10 is closer than that between 10 and 50 or 50 and 100.
How can I edit the graph?

回答(1 个)

Cris LaPierre
Cris LaPierre 2023-11-27
编辑:Cris LaPierre 2023-11-27
You will need to turn your System Size values into categoricals. You haven't shared your data, so here's a simple example.
% What you currently have
systemSize = ([ones(4200,1);10*ones(500,1);50*ones(100,1);100*ones(50,1)]);
histogram(systemSize)
xticks([1 10 50 100])
% With x data type as categoricals
catSystemSize = categorical(systemSize);
histogram(catSystemSize)
  5 个评论
Cris LaPierre
Cris LaPierre 2023-11-27
Your code is fine, except that you still need to convert your X values to categoricals. This allows the x position to be set by group number instead of numeric value.
This is the only line of code that needs to change.
bar(categorical(system_sizes), all_capex_values, 'grouped');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Model Identification 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by