Control Text Label on plot with categorical axis

Hi all,
I am using "plot" to create a plot with lines and scatter points. The x-axis is numerical, the y-axis categorical. I would like to add labels to each datapoint, but I am having trouble positioning them. I would like to add a vertical offset, but since the y-axis is categorical I don't know how. I am using the text() command.
Is there any other way to specify the y-location of a label, perhaps by a pixel offset?
Thank you very much!
Example Code:
y={'LGPS', 'LGPS'};
x=[37.19, 40];
quellen={'Wang 2019', 'Wu 2020'};
y=categorical(y);
plot(x,y,'or');
hold on
text(x,y,quellen, 'vert','bottom','horiz','center')

 採用された回答

Chad Greene
Chad Greene 2021 年 3 月 11 日

1 投票

Have you tried using the 'vertical' and 'horizontal' alignment options?
plot(5,6,'o')
text(5,6,'default text')
text(5,6,'above the dot!','vert','bottom','horiz','center','fontangle','italic')

5 件のコメント

Lovis Wach
Lovis Wach 2021 年 3 月 11 日
編集済み: Lovis Wach 2021 年 3 月 11 日
Thank you, I must have overlook those in documentation!
The above option does work however the label is still clipping the text, do you know if I can influence the distance?
Chad Greene
Chad Greene 2021 年 3 月 11 日
Can you post a minimal working example?
Lovis Wach
Lovis Wach 2021 年 3 月 11 日
I edited the main post to include some simple code, thank you for your help!
Chad Greene
Chad Greene 2021 年 3 月 11 日
編集済み: Chad Greene 2021 年 3 月 11 日
Oh, I see what you mean. This isn't a very elegant fix, but what about adding an empty text line below each label? You could do that like this:
quellen={{'Wang 2019';' '}, {'Wu 2020';' '}};
If that puts it too far away from the center of the dot, you could set the vertical alignment to 'middle'.
Lovis Wach
Lovis Wach 2021 年 3 月 11 日
nice! That does it! Thank you so much, marked as solution :)

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

その他の回答 (0 件)

カテゴリ

質問済み:

2021 年 3 月 11 日

編集済み:

2021 年 5 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by