Is it possible to create a bar graph with different x-Axis scale/labeling?

4 ビュー (過去 30 日間)
Jan Böttner
Jan Böttner 2023 年 8 月 10 日
コメント済み: Jan Böttner 2023 年 8 月 10 日
Hi,
I am trying to create a bar graph that looks like this:
On the x-Axis I would like to have the bars for WP on the very left with one bar distance to the bars from -12 to 20°C and then again the bars for SHVK on the very right with one bar distance.
Furthermore I am working with a table and I was wondering if it would work if i write WP and SHVK in the collumn for the temperature or if i'd have to use a different way of working with the table. Because at the moment I have 0 as the temperature but that gives out a wrong graph as there are three values for 0 on the x-Axis.
I have attached the table I am working with. I want to plot out.combinednew.([3,9,12]).
Thanks!

採用された回答

dpb
dpb 2023 年 8 月 10 日
編集済み: dpb 2023 年 8 月 10 日
Set the first/last x values to min(x)-2/max(x)+2, respectively, then set the ticklabels for those two manually.
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12]; % from bar() example for grouped
x=[0:length(y)-1]-2; % simulate similar x
y=[y(1,:);y;y(end,:)]; y(1,end)=0; y(end,1)=0; % augment y similar to desired
x=[x(1)-2 x x(end)+2]; % fixup the x vector with gap
subplot(2,1,1)
bar(x,y); % default look to match
subplot(2,1,2) % now fixup the ticklabels as desired
bar(x,y); % base plot
LABELS={'WP','SHVK'}; % the specific group labels wanted
hAx=gca; % get the axis handle
hAx.XTickLabels([1,end])=LABELS; % write those two in place of default
  1 件のコメント
Jan Böttner
Jan Böttner 2023 年 8 月 10 日
thanks a lot, that's exactly what I was looking for! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by