Creation of line between axis and point in scatterplot?

8 views (last 30 days)
The question pretty much says it all. How do you visualise a line between any point (even a moving point), directly towards the x-axis?

Answers (1)

dpb
dpb on 3 Nov 2013
doc line % maybe???
There's a topic on animation techniques in the section on enhancing graphics that may be useful as well...
But in general,
hold on
line([x x]', [y 0]')
will add the line. For more generality, use
yl=ylim; yl=ylim(1);
for the 0 to get the value of the y axis lower limit
Image Analyst noted that--
If it's a moving point, you'll have to get the handle to the line so you can delete it when you draw the next one.
hLine = line(......
% move coordinates, then
% delete last line
delete(hLine);
% Draw new line
hLine = line(................
To which dpb agreed but noted that there's an easier way:
Do need the handle, yes...but only need to update the data point(s) that are moving/moved from one to another in the [x|y]data properties, not actually delete old/draw new but just change the data in the one...that automagically erases the other.
hL=line([x x]', [y 0]');
...something that changes x and y...
set(hL,'xdata', [x x], 'ydata', [y 0]);
  2 Comments
Image Analyst
Image Analyst on 3 Nov 2013
Then please mark it as "Accepted" so dpb can get credit for it.

Sign in to comment.

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!