Link specific coordinates to a color when plotting them
古いコメントを表示
Hello I am wondering if there is a way to link specific coordinates in a matrix to always be plotted in a specific color. like if I had the set of coordinates shown below and i want the first 4 sets to always be plotted in red and the next 3 always plotted in green whenever they are being plotted so that even if I clear the axes and replot those coordinates will always appear in the color they were set to.
A = [38.8197976955836 -29.0434116907097
-37.0532684880158 0.644925865563445
-4.49735986053992 57.3402937422674
-43.7442096431328 38.5935144262550
41.5359946082739 41.4696332098067
57.3572679057450 8.87552592324304
-29.8320366435934 -43.1286701525403];
採用された回答
その他の回答 (1 件)
When you use plot(x,y) it returns 1 handles and you cannot specify different colors to objects within the same handle.
You can use gscatter() (stats toolbox) to create grouped scatter points where you can specify the color (and size of markers) of each group.
h = gscatter(A(:,1),A(:,2),[1 1 1 1 2 2 2],[1 0 0; 0 1 0])
% _______________ here we define the groups by row
% ______________ here we define the colors for each group
If you don't have stats toolbox, you can separate the rows of A and plot them as individual objects.
h1 = plot(A(1:4,1),A(1:4,2), 'ro');
hold on
h2 = plot(A(5:end,1),A(5:end,2), 'go');
4 件のコメント
Vance Blake
2019 年 9 月 8 日
編集済み: Vance Blake
2019 年 9 月 8 日
If you're just plotting scatter points, then yes, you can replace plot() with scatter() but you also need to check that the other inputs OK.
David Hill's answer might suit your needs better since it does not spit the data into different graphics handles.
Vance Blake
2019 年 9 月 8 日
Adam Danz
2019 年 9 月 8 日
Yeah, both gscatter() and scatter() have pros and cons that vary based on the context of the problem. Based on your context (from another post), I think scatter() will keep your data more organized.
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!