Plotting cartesian coordinates of animal paths

Hello everyone,
I have spent the last few weeks ironing out the complicated parts of a (once dead) data set. All of the difficult mathematics are done and I have a beautiful code that spits out a perfect, time-stamped matrix. I want to plot these x and y coordiantes (the 3rd and 4th columns of my data); however, I have gone through the different posts on here re: plotting cartesian points and have not yet found a working solution.
My data looks something like this:
0 0 0 0
1 0.20 -3.99640 -0.265350
2 0.40 -1.10210 0.462070
3 0.60 -2.43890 0.371960
4 0.80 -0.2320 -0.553330
5 1 0.0904320 -1.32830
6 1.20 -14.1930 0.138860
Column1 is an index
Column2 is a timestamp
Column3 is the animal's position along the x-axis (x coordinate)
Column4 is the animal's position along the y-axis (y coordinate)
Other solutions posted on here seem to consider the X and Y coordinates separately, rather than as two defining features of a single point in space. I suppose in that way, my goal is plot the index value and it's affiliated x and y values (though this may just be semantics).
At the end of the day, my goal is take several hundred iterations of this type of path data and generate a heat map to compare path features between samples.
Many thanks.

 Accepted Answer

Why can't you just use plot() to plot the x and y coordinates and use text() to put the index number beside the point?
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
D = [0 0 0 0
1 0.20 -3.99640 -0.265350
2 0.40 -1.10210 0.462070
3 0.60 -2.43890 0.371960
4 0.80 -0.2320 -0.553330
5 1 0.0904320 -1.32830
6 1.20 -14.1930 0.138860]
x = D(:, 3);
y = D(:, 4);
plot(x, y, 'bo-', 'LineWidth', 2, 'MarkerSize', 12);
grid on;
title('Animal Positions', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% Now plot index numbers along side the markers.
hold on;
for k = 1 : size(D, 1)
string = sprintf(' Time Point %d', k);
text(x(k), y(k), string, 'FontSize', 14, 'Color', 'm');
end
% Draw in the X and Y axis
line(xlim, [0,0], 'Color', 'k', 'LineWidth', 3);
line([0,0], ylim, 'Color', 'k', 'LineWidth', 3);

4 Comments

This is a great start. Each time I had tried to use the plot f(x), it produced errors or meaningless plots. What is the "bo-" item you have on line 11?
(*nevermind. blue, solid, line.)
If I were to plot many iterations of this type of path on the same plot, is it possible to produce an "overlay" effect, which shows the frequency of occurrence at each position?
Ideally, I would like to have an XY plane that is 300.00 x 300.00 units - each unit, in this case, would be .01 x .01. The plotting space would effectively be 30,000 x 30,000. In my vision, each .01 x .01 cell would have some value 'f', where f = # of times any animal moved over that space. How would you go about this?
If you have the Statistics and Machine Learning Toolbox, I would definitely check out hist3(). It produces a 2 dimensional histogram (despite its name), or count, of how many times your data points fall into certain auto-defined or user-defined ranges. I would think that if you have a dense enough scatterplot, that you could get a decent heatmap that way.
Otherwise, there is probably some kind of heatmap algorithm out there that can build one from a huge number of unique x-y points. I'm sure it's out there but I've not had occasion to use it yet myself. If you find it though, comeback here and let us know. The 2D histogram will be the actual counts and not do any "smoothing" of "in-between" regions like some official heat map creation software might do.
In weather forecasting (geo-spatial statistics) they build heat maps (literally!) using Kriging.
Thanks for all of your help, Image Analyst. I will report back with my completed methods. You are awesome.
Hi :-)
do you have completed method you can share? i need to do this also...
Best,
Lital

Sign in to comment.

More Answers (0)

Categories

Asked:

on 13 Oct 2015

Commented:

on 3 Sep 2020

Community Treasure Hunt

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

Start Hunting!