I have three regions on a ternary plot drawn as trace1, trace2 and trace3. My question is, if I plot a series of datapoints on the ternary plot, one at a time in a for loop, how can I find which region a given datapoint is located in at the end of each iteration? In my example, the coordinates of the first tuple is in the top region (region1), the second in the bottom left region (region2), and the third in the bottom right region (region3). In reality, I have millions of datapoints for which I need to retrieve the region of in a more complicated diagram, so I donโt need the plot to be rendered at the end of each iteration, and I would like to know how to clear the last datapoint before another iteration.
import plotly.graph_objs as go
data_points = [(60, 20, 20), (20, 70, 10), (30, 20, 50)]
trace1 = go.Scatterternary( a=[40, 100, 40], b=[60, 0, 0], c=[0, 0, 60], fill='toself', name='region1' )
trace2 = go.Scatterternary( a=[0, 40, 40, 0], b=[100, 60, 30, 50], c=[0, 0, 30, 50], fill='toself', name='region2' )
trace3 = go.Scatterternary( a=[40, 0, 0, 40], b=[30, 50, 0, 0], c=[30, 50, 100, 60], fill='toself', name='region3' )
for point in data_points:
data_point = go.Scatterternary( a=[point[0]], b=[point[1]], c=[point[2]], name='datapoint' )
fig = go.Figure( data=[trace1, trace2, trace3, data_point] )
fig.show( )
Below is the figure made by the third iteration showing the datapoint that is in region3. So, for example, I would like the for loop to print โregion3โ at the third iteration.