I’m trying to create a table output that changes depending on where a scatter point lies in a graph.
I have done something similar in the past with rectangles but am struggling with the polygons as they can have multiple x and y ranges.
I want the output to give the Location ID (z) and soil type (ME, MI etc….) in a table that will change if I bring in a different CSV file. I have a bit of psuedo code at the bottom to show the direction I was going in but I’m probably wrong.
import matplotlib.pyplot as plt import numpy as np import pandas as pd from matplotlib.patches import Polygon import math #Bring in the CSV file LLPL=pd.read_csv("CSV_File",delimiter=',') #Isolate columns needed from CSV file and plot graph y=LLPL.Plasticity_Index z=LLPL.Location_ID img = plt.imread("LLPL_Picture.png") fig, ax=plt.subplots() ax.imshow(img, extent=(0, 100, 0, 80)) plt.plot(x, y,'.') #Define polygon coordinates ME=((91.5,0),(100,0),(100,58.5),(91.5,52)) CE=((91.5,52),(100,58.5),(100,80),(93,80),(91.5,78)) MV=((71,0),(91.5,0),(91.5,52.5),(71,37.5)) MH=((50.5,0),(71,0),(71,37.5),(50.5,22)) CV=((71,37.5),(91.5,52),(91.5,78),(71,58.5)) CH=((50.5,22),(71,37.5),(71,58.5),(50.5,40)) MI=((35,0),(50.5,0),(50.5,22),(35,11)) CI=((35,11),(50.5,22),(50.5,40),(35,24)) ML=((9,0),(35,0),(35,11),(28,6),(15,6),(8,0)) CL=((15,6),(28,6),(35,11),(35,25),(15,6)) #Add polygons to the graph poly1=ax.add_patch(Polygon(ME,closed=True,facecolor='blue',alpha=0.5)) poly2=ax.add_patch(Polygon(CE,closed=True,facecolor='green',alpha=0.5)) poly3=ax.add_patch(Polygon(MV,closed=True,facecolor='red',alpha=0.5)) poly4=ax.add_patch(Polygon(MH,closed=True,facecolor='orange',alpha=0.5)) poly5=ax.add_patch(Polygon(CV,closed=True,facecolor='yellow',alpha=0.5)) poly6=ax.add_patch(Polygon(CH,closed=True,facecolor='pink',alpha=0.5)) poly7=ax.add_patch(Polygon(MI,closed=True,facecolor='purple',alpha=0.5)) poly8=ax.add_patch(Polygon(CI,closed=True,facecolor='grey',alpha=0.5)) poly9=ax.add_patch(Polygon(ML,closed=True,facecolor='lightblue',alpha=0.7)) poly10=ax.add_patch(Polygon(CL,closed=True,facecolor='black',alpha=0.5)) plt.show() #def soilclassification(): # if x = Nan #return 'Non Plastic' # elif (x,y) lies in polygon #return 'ME' #elif (x,y) lies in polygon #return 'MI' #etc.....
This currently returns this:
Graph showing scatter points within polygons