Draw lines from both axis to point in plot

15 ビュー (過去 30 日間)
Marc
Marc 2018 年 11 月 16 日
回答済み: Mehmet Cem TOKER 2021 年 10 月 4 日
Hello
I imported a .csv file and plotted its values in a (x,y) plot. Now I want to highlight a specific point by drawing both a vertical and a horizontal line from that point to it's value on the x and y axis and also display those values. Has someone an idea how I can achieve this?
Cheers Marc

回答 (2 件)

Adam Danz
Adam Danz 2018 年 11 月 16 日
編集済み: Adam Danz 2020 年 4 月 4 日
Draw vertical and horizontal reference lines
First you should set the axis limits, then plot the lines. Here's a demo
figure
point = [0.7, 0.5]; % Here the point that will have the reference lines
axLims = [0 1 -2 2]; %[x-min, x-max, y-min, y-max] axis limits
plot(point(1), point(2), 'o')
xlim(axLims(1:2));
ylim(axLims(3:4));
hold on
plot([point(1), point(1)], [axLims(3), point(2)], 'k-') %vertical line
plot([axLims(1), point(1)], [point(2), point(2)], 'k-') %horizontal line
Display coordinates of point
text(axLims(1), axLims(3), sprintf('point (%.2f, %.2f)', point), 'HorizontalAlignment', 'Left', 'VerticalAlignment', 'Bottom')
  1 件のコメント
Yash Runwal
Yash Runwal 2019 年 5 月 21 日
This is an accurate solution. Thanks!

サインインしてコメントする。


Mehmet Cem TOKER
Mehmet Cem TOKER 2021 年 10 月 4 日
worked for me. thank you^^

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by