This happens because you have two nested for
loops: the first loop iterates over each row
, whereas the second loop makes the scatter plot appear on every subplot. This in turn means that every plotted parameter will appear on every subplot. To avoid this, you should avoid the double for
loop.
I'm not sure I understand exactly what you want to achieve, but this should at least get you on your way.
import arcpy
import os
import matplotlib
import matplotlib.pyplot as plt
#Variables
FC = arcpy.GetParameterAsText(0) #feature class
P1_fld = arcpy.GetParameterAsText(1) #score field to chart
P2_fld = arcpy.GetParameterAsText(2) #score field to chart
plt.subplots_adjust(hspace=0.4)
nsubp = int(arcpy.GetCount_management(FC).getOutput(0)) #pulls n subplots from FC
last_val = object()
#Sub-plot loop
cur = arcpy.SearchCursor(FC, "", "", P1_fld)
i = 0
x = 1
for row in cur:
y = row.getValue(P1_fld)
if row.OBJECTID != last_val:
i += 1
ax = plt.subplot(nsubp, 1, i) # Create a subplot.
ax.scatter(x, y, s=5, color='blue'); # Generate the Scatter Plot.
oid = str(row.getValue('OBJECTID'))
figPDf = r"filepath.pdf" # Save the Scatter Plot to PDF.
plt.savefig(figPDf)
del row, cur
os.startfile("filepath.pdf")