Highlight 3 points in scatter plot with label on it

15 次查看(过去 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

采纳的回答

Adam Danz
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)
190630 083557-Figure 6.jpg
  2 个评论
Phoenix
Phoenix 2019-6-30
编辑:Phoenix 2019-6-30
SOrry for confusion. Is it possible to retain the arrow and have a separate color (filled) for the three points?
Adam Danz
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
190630 090828-Figure 6.jpg

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by