From ebba7a48fa412198bd4c82818799e2e3b559c4c2 Mon Sep 17 00:00:00 2001 From: Paul Garlick Date: Fri, 10 Jul 2020 13:48:52 +0100 Subject: python: slope.py: Use maximum y-value in polyfit and plot functions. * python/slope.py (plot_curve)[MY]: New argument. --- python/slope.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/python/slope.py b/python/slope.py index cd1dea7..da6d314 100755 --- a/python/slope.py +++ b/python/slope.py @@ -122,10 +122,11 @@ def detach_display(): fig.canvas.callbacks.disconnect(cid) #print(xMarker) -def plot_curve(PX): +def plot_curve(MY, PX): """ Fit straight line to channel elevation data. Pixel size PX is - used to convert pixel indices to co-ordinate values. + used to convert pixel indices to co-ordinate values. The maximum + co-ordinate value in the y-direction is MY. """ # sort markers by y value #yx = list(zip(yMarker, xMarker)) @@ -160,13 +161,14 @@ def plot_curve(PX): # Add to list. Repeat. # Fit with polyfit - m, c = np.polyfit([499.75 - y*PX for y in ych], zch, 1) + m, c = np.polyfit([MY - y*PX for y in ych], zch, 1) print('gradient =', m, 'intercept =', c) + print('MY =', MY) fig, ax = plt.subplots() - line1, = ax.plot([499.75 - y*PX for y in ych], zch) - line2, = ax.plot([499.75 - y*PX for y in ych], - [c + m*499.75 - m*y*PX for y in ych], '--') + line1, = ax.plot([MY - y*PX for y in ych], zch) + line2, = ax.plot([MY - y*PX for y in ych], + [c + m*MY - m*y*PX for y in ych], '--') ax.set_xlabel('Distance / m') ax.set_ylabel('Height / m') ax.set_title('Channel profile') @@ -210,7 +212,7 @@ while (True): elif(input_str == "m"): detach_display() elif(input_str == "p"): - plot_curve(DY) + plot_curve(ytp[-1], DY) elif(input_str == "s"): save_xyz() -- cgit