I want to create a plot using X Y coordinates

69 ビュー (過去 30 日間)
George Sfinarolakis
George Sfinarolakis 2021 年 2 月 2 日
コメント済み: Maheedhar Korimi 2022 年 10 月 31 日
I have 51 nodes that each one of them has X Y coordinates. I used the command: plot(x,y, 'd') but I would like the figure to show me the number of each node next to the diamond.For example the first node I'd like to have the number 1 next to it, the second the number 2 etc. Also I'd like the first node to be different shape or colour from the others. Do I have to use two different types of plot or it can be done in the same command? Thank you for your time.

採用された回答

Star Strider
Star Strider 2021 年 2 月 2 日
編集済み: Star Strider 2021 年 2 月 2 日
Use the text function.
Example: —
x = rand(1,5);
y = rand(1,5);
nrc = compose('%2d',1:numel(x)); % Coordinate Numbers (Cell Array)
cm = jet(numel(x)); % Use The ‘colormap’ Of Your Choice
figure
scatter(x, y, 75, cm, 'd', 'filled')
grid
text(x, y, nrc)
EDIT — (2 Jan 2021 at 19:18)
Changed from plot to scatter since it provides more options, especially with respect to colouring the points. There are a limited number of shapes, so I would just go with changing the colours. The sizes of the plotted points can chnage with the colours with scatter.
  2 件のコメント
George Sfinarolakis
George Sfinarolakis 2021 年 2 月 2 日
Thank you very much for your time! It worked
Star Strider
Star Strider 2021 年 2 月 2 日
As always, my pleasure!

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

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 2 月 2 日
plot(x, y)
text(x, y, string(1:numel(x)))
Now scatter(x(:), y(:), Pointsize, C)
where C is a numel(x) by 3 color array in which you set the first row to be different from the others. You can also set the marker shape on the call.
Limitations:
  • all of the markers for the same plot line must be the same color and shape (unless I am forgetting a recent change)
  • all of the markers for a single scatter call must be the same shape

Matt J
Matt J 2021 年 2 月 3 日
x=rand(10,1); y=rand(10,1);
n=numel(x);
plot( graph(1:n,1:n),'LineStyle','none','Marker','d','XData',x,'YData',y);
  2 件のコメント
George Sfinarolakis
George Sfinarolakis 2021 年 2 月 3 日
That's also perfect. Thank you!
Maheedhar Korimi
Maheedhar Korimi 2022 年 10 月 31 日
Hi Matt, can I get 95 percentile in this data? maybe a circle representing 95 percentile of this data?
for example, consider 100 nodes, which is represented by (x,y) coordinates. How can I locate 95 percentile of this data?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by