Azzera filtri
Azzera filtri

Highlight 3 points in scatter plot with label on it

15 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Adam Danz
Adam Danz il 30 Giu 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 Commenti
Phoenix
Phoenix il 30 Giu 2019
Modificato: Phoenix il 30 Giu 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 il 30 Giu 2019
Modificato: Adam Danz il 30 Giu 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

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by