Need help with direction field plot

I'm relatively new to matplotlib so I need some help. I'm trying to make a
direction field plot for visualzing solutions to differential eqs. My first
attempt at a simple plot came out all right but I can't figure out why the
plotted lines are not the same length. The block of code that does all of
the work is...

for x in ax1.xaxis.iter_ticks(): #Iterate
over x-ticks
    for y in ax1.yaxis.iter_ticks(): #iterate
over y-ticks
        
# Solve for local slope at point to be evaluated (dy/dx)

        yp = 9.8 - ((np.float(y[1]))/4) #yp = y` as
in dy/dx
        
# Plot line based on slope

        cpx = np.float(x[1]) #cpx = x-coord of line center,
convert x-tick value to float
        cpy = np.float(y[1]) #cpy = y-coord of line center,
covnert y-tick value to float

        a = np.arctan(yp) #a = angle between line and
horizontal
        
        px = np.cos(a)*(L/2) #px = x offset from line center to
end
        py = np.sin(a)*(L/2) #py = y offset from line center
to end

        tpx = cpx + px #tpx = x-coord of right hand
end of line
        tpy = cpy + py #tpy = y-coord of right hand
end of line

        bpx = cpx - px #bpx = x-coord of left hand end
of line
        bpy = cpy - py #bpy = y-coord of left hand end
of line
        
        Length = np.sqrt(((tpx-bpx)**2)+((tpy-bpy)**2))
       #just a quick check of the line length accoring to the coordinates of
the ends

        ax1.plot([bpx, tpx], [bpy, tpy], color='black', linewidth=0.75)

As you can see in the attached figure (see below), the lines seem to plot in
the right locations and right angles but the lengths are not constant (not
intended - seem to be twice as long near the middle of the chart). Am I
missing something obvious? Why are the lines near the center of the chart
longer? Thanks in advance for any help provided.

-Ryan

http://old.nabble.com/file/p28859981/img1.png

···

--
View this message in context: http://old.nabble.com/Need-help-with-direction-field-plot-tp28859981p28859981.html
Sent from the matplotlib - users mailing list archive at Nabble.com.