Add text to data points in a circle plot

6 ビュー (過去 30 日間)
Juan David Mateus
Juan David Mateus 2020 年 5 月 4 日
コメント済み: Juan David Mateus 2020 年 5 月 4 日
Hello,
I have a 26x26 matrix called mdist of distances of 26 banks with themselves which i plot like this:
figure;
x=graph(mdist);
plot(x,'layout','circle');
The thing is that i need to put the names of each bank in the data points so it looks like the following(mine does not have those names)
  2 件のコメント
Rik
Rik 2020 年 5 月 4 日
You can generally use the text function to insert texts to your plot.
Juan David Mateus
Juan David Mateus 2020 年 5 月 4 日
yeah, but i have no idea how to use it in this case, if it was a scatter plot with 2 axis i would just put the values in the x,y of the text function, but in this case as i have a distances matrix, i do not know how to asign each dot its respective name, Thanks!

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 4 日
編集済み: Ameer Hamza 2020 年 5 月 4 日
If you get the handle of GraphPlot
p = plot(G,'layout','circle');
Then you can get the x and y location of each node using
X = p.XData
Y = p.YData
However, If you want to add text at an arbitrary point, then you can make the xtick values visible and then use text() to add the text at the location you want
figure;
ax = axes();
A = randi([1 10], 50);
G = graph(A,'upper');
p = plot(G,'layout','circle');
ax.XAxis.TickValuesMode = 'auto';
ax.YAxis.TickValuesMode = 'auto';
text(0, 0.5, 'myText', 'FontSize', 14, 'Color', 'r')
And then you can again make them invisible using
ax.XAxis.TickValues = []
ax.YAxis.TickValues = []
  2 件のコメント
madhan ravi
madhan ravi 2020 年 5 月 4 日
Clever interpretation!
Juan David Mateus
Juan David Mateus 2020 年 5 月 4 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by