フィルターのクリア

Highlight 3 points in scatter plot with label on it

19 ビュー (過去 30 日間)
Phoenix
Phoenix 2019 年 6 月 30 日
編集済み: Adam Danz 2019 年 6 月 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 Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by