2

I have a pandas dataframe with two columns and around 50 rows. I want to create a scatter plot of the two columns but I also want to have the datapoints connected to each other. So I did something like this:

plt.plot(df['colA'], df['colB'], 'o-')
plt.show()

I am getting an output like this: enter image description here

But I want to have data points connected to each other so as to give an ellipse circumscribing the data points. I feel like the reason I'm getting this plot is that in the dataframe that's how the datapoints are sequenced. Is there a way to deal with this?

Any help would be appreciated! Thanks in advance

2
  • 5
    It looks like you'd need to sort them into the correct order. You could do this by creating another column corresponding to the angle around the circle. To calculate this, pick a point, (xc, yc), that's within the circle (say the vector average of all the points) , and then A = atan2(y-yc, x-xc), and order by column A. Commented Feb 7, 2020 at 21:37
  • 4
    Use ConvexHull to get this done: stackoverflow.com/questions/36763853/… Commented Feb 7, 2020 at 21:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.