I have created figures similar to this one here:
My goal here is to take each blue point and calculate the shortest distance it would take to get to any point on the red line. Ideally, this could be used to select the x% closest points or those falling within a certain distance, but the primary issue here is calculating each distance in the first place.
The points were taken from a data file and plotted as such:
data = np.loadtxt('gr.dat') ... ax.scatter(data[:,0],data[:,1])
whereas the red line is a calculated Baraffe track where all points used to create the line were stored in a dat file and plotted via:
df=pd.read_csv('baraffe.dat', sep="\s+", names= ['mass', 'age', 'g', 'r', 'i'])
df2 = pd.DataFrame(df, columns=["mass", "age", "g", "r", "i"])
df2['b_color'] = df2['g'] - df2['r']
df2.plot(ax=ax, x='b_color',y='g', color="r")
...`
This is my first attempt at using pandas so I know my code could definitely be optimized and is likely redundant, but it does output the figure attached.
Essentially, I want to calculate the smallest distance each dot would have to move (in both x and y) to reach any point on the red line. I did try and mimic the answer in (here) but I am unsure how to apply that definition to a dataframe or larger array without always getting a TypeError. If there is any insight to this I would greatly appreciate it, and thank you!