Highlight 3 points in scatter plot with label on it
19 ビュー (過去 30 日間)
古いコメントを表示
Hello,
How do I highlight 3 points with labels and coordinates on it (goal is similar to one below) from my scatter plot? Here is my code as well the data (excel attached). Thank you.
Edit : retain the arrows and have a different color (filled) for the three points.
x = (xlsread('Question','A2:A101'));
y = (xlsread('Question','B2:B101'));
figure(6)
scatter(x,y)
ylabel('Fuel consumption [L/yr]');
xlabel('Levelised Cost of Energy ($/kWh)');
legend ('Generation 200');
box on
0 件のコメント
採用された回答
Adam Danz
2019 年 6 月 30 日
There are several ways to go about this such as by using text(), annotation(), gname(), labelpoints() and other methods. Here's an example using text(). You can get the coordinates directly from your data or by using the data cursor .
x0 = x(1);
y0 = y(1);
label = sprintf(' \\leftarrow min LCOE (%.3f,%.0f)',x0,y0);
text(x0,y0,label,'HorizontalAlignment','Left','VerticalAlignment','middle','FontSize',8)
x1 = 0.57587; %obtained using Data Cursor
y1 = 97989.4; % "
label = sprintf(' \\leftarrow trade-off (%.3f,%.0f)',x1,y1);
text(x1,y1,label,'HorizontalAlignment','Left','VerticalAlignment','middle','FontSize',8)
2 件のコメント
Adam Danz
2019 年 6 月 30 日
編集済み: Adam Danz
2019 年 6 月 30 日
Of course.
x = (xlsread('Question','A2:A101'));
y = (xlsread('Question','B2:B101'));
figure(6)
h = scatter(x,y); % <---- store the handle to your scatter object
ylabel('Fuel consumption [L/yr]');
xlabel('Levelised Cost of Energy ($/kWh)');
box on
% Add text
x0 = x(1);
y0 = y(1);
label = sprintf(' \\leftarrow min LCOE (%.3f,%.0f)',x0,y0);
text(x0,y0,label,'HorizontalAlignment','Left','VerticalAlignment','middle','FontSize',8)
x1 = 0.57587; %obtained using Data Cursor
y1 = 97989.4; % "
label = sprintf(' \\leftarrow trade-off (%.3f,%.0f)',x1,y1);
text(x1,y1,label,'HorizontalAlignment','Left','VerticalAlignment','middle','FontSize',8)
% fill in the markers
hold on
plot([x0,x1],[y0,y1],'bo','MarkerFaceColor','r')
% add legend
legend (h, 'Generation 200'); %<---- specify object handle
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!