Highlight 3 points in scatter plot with label on it

18 views (last 30 days)
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

Accepted Answer

Adam Danz
Adam Danz on 30 Jun 2019
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 Comments
Phoenix
Phoenix on 30 Jun 2019
Edited: Phoenix on 30 Jun 2019
SOrry for confusion. Is it possible to retain the arrow and have a separate color (filled) for the three points?
Adam Danz
Adam Danz on 30 Jun 2019
Edited: Adam Danz on 30 Jun 2019
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!