0

I am tracking the movements of an avian animal. I have detection points on an xy plot. I want to connect the previous detected point to the next detection, regardless of direction. This will assist with removing extraneous detections.

Data Sample:

Sample input The goal is to have a line from the previous data point to the next point.

Sample output

Unsuccessful method 1:

plt.figure('Frame',figsize=(16,12))
plt.imshow(frame)
plt.plot(x, y, '-ro', 'd',markersize=2.5, color='orange')

Method 1 output

Unsuccessful method 2:

plt.plot(np.sort(x), y[np.argsort(x)], '-bo', ms = 2)

Method 2 output

Bat_gal
  • 33
  • 1
  • 5
  • Can you describe a sample output please? For example can you give a sample data input, and an example of how you want the data to look with that data? – chadmc Mar 18 '20 at 22:18
  • @chadmc I added the sample input and output above. – Bat_gal Mar 18 '20 at 22:58
  • Sorry I meant it would help if you print your data in a python form. – chadmc Mar 18 '20 at 23:20
  • 1
    It's clear from Method 1 output that you are passing far more data points to `plot` than you have in the sample input. I'm not sure but I think method 1 works. What happens if you try it with x and y coming from your sample input? – Oliver Dain Mar 18 '20 at 23:41
  • I ran the code again with fewer points and better filtering. Looks like it was an error on my end with the poor filtering of extraneous points. Thanks! – Bat_gal Mar 19 '20 at 16:30

1 Answers1

0

I used your sample data and make a plot with method 1 (but with pandas) and the output was as you expected. I don't understand why you have an unsuccessful result.

data = [{'frame': 1, 'x': 5, 'y': 15},
 {'frame': 4, 'x': 10, 'y': 15},
 {'frame': 5, 'x': 15, 'y': 15},
 {'frame': 6, 'x': 20, 'y': 15},
 {'frame': 7, 'x': 23, 'y': 20},
 {'frame': 8, 'x': 25, 'y': 25},
 {'frame': 11, 'x': 20, 'y': 23},
 {'frame': 15, 'x': 15, 'y': 20},
 {'frame': 18, 'x': 8, 'y': 18},
 {'frame': 19, 'x': 8, 'y': 10},
 {'frame': 20, 'x': 12, 'y': 7}]
df = pd.DataFrame(data).sort_values('frame')
df.plot(x='x', y='y')

enter image description here

jjsantoso
  • 1,586
  • 1
  • 12
  • 17