Andrei Berceanu
Andrei Berceanu

Reputation: 361

Extract specific paths from matplotlib contour plot

I have the following contour plots:

fig, axes = plt.subplots(1,6, figsize=(18,3))

for idx in range(6):
    axes[idx].contour(KX[kxl:kxr,kxl:kxr],KY[kxl:kxr,kxl:kxr],eigs[kxl:kxr,kxl:kxr,idx].real, levels=[0])
    axes[idx].set_xlabel(x_label_k)

axes[0].set_ylabel(y_label_k)

6 eigenvalue contours

Overlapping them results in the following image:

fig, ax = plt.subplots(1,1, figsize=(4,4))

for idx in range(6):
    ax.contour(KX[kxl:kxr,kxl:kxr],KY[kxl:kxr,kxl:kxr],eigs[kxl:kxr,kxl:kxr,idx].real, levels=[0])

ax.set_xlabel(x_label_k)
ax.set_ylabel(y_label_k)

overlapped contours

From the above image, I am interested in plotting just the 4 "circle-like" shapes that are shown in the edited image below:

edited circles

If possible, I would like the pairs of (kx, ky) points that make up these elongated circles, without any of the points from the other artifacts.

I have seen that there is a way of extracting point values from a contour plot along the lines of this question, however, that gives me a set of (2000,2000) points which I have no idea how to filter. I was thinking maybe something can be done based on paths from the contour plots?

Note that one can actually see where the circle-shapes originate in the row of 6 plots, but the problem is that in order to make up the 2 smaller inner circles one has to combine subplots 2,3,4 and 5. For the larger outer ones, it is simpler as they are relative well separated in subplots 5 and 6.

Upvotes: 1

Views: 388

Answers (1)

Developer
Developer

Reputation: 8400

While you have set of points extracted from contours, try RANSAC. An implementation in C# to extract circles from noisy points is given here. A general and simple Python implementation is given here.

You may also try Least Square Circle Fitting for which an example in Python is given here.

Good Luck.

Upvotes: 2

Related Questions