Reduce distance between vertical axis categorical variables plot

2 ビュー (過去 30 日間)
sittmo
sittmo 2022 年 10 月 7 日
回答済み: Jiri Hajek 2022 年 10 月 7 日
Say I have the following code:
% convert y axis to categorical
y_cat = categorical({'Cat (A)'; 'Cat (B)'; 'Dog (A)'; 'Dog (B)'});
% reorder y axis
y_cat = reordercats(y_cat,{'Cat (A)'; 'Cat (B)'; 'Dog (A)'; 'Dog (B)'});
plot([-0.0904719; -0.0360067; -0.1152766; 0.0423135], y_cat);
hold on
% make horizontal error bars
hline = errorbar([-0.0904719; -0.0360067; -0.1152766; 0.0423135],y_cat,[0.0492568;0.0467123;0.0829603;0.0509949],[0.0492568;0.0467123;0.0829603;0.0509949],'horizontal');
hline.Bar.LineStyle = 'dashed';
% Italicize y axis tick labels
ax=gca;
ax.TickLabelInterpreter='tex';
ax.YTickLabel={'\it Cat (A)', '\it Cat (B)', '\it Dog (A)', '\it Dog (B)'};
% make vertical line at 0
xline(0, ':', 'linewidth', 1);
And after some point and click editing in Figures, I get the current output:
What I'd like to do, however, is reduce the distance between different categorical variables, for example the Dog (B) and Dog (A) horizontal lines should be close to each other, and similarly for the Cat group. I want something in the following figure (edited using paint to illustrate my desired output):
How can I achieve something like this?

回答 (1 件)

Jiri Hajek
Jiri Hajek 2022 年 10 月 7 日
You could do this by using numerical Y axis values instead of categorical, and then apply your own YTicks.

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by