SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: OffbeatPatriot <ja...@em...> - 2008年11月27日 04:33:19
I wanted to make a function to take another function that takes a 2d-vector
and returns a 2d-vector, x and y boundaries, and a resolution, and plot the
slope field. However all I get is a blank plot over a small range and some
vertical and horizontal lines. This is my code, if you know differential
equations with the function I'm using you should see a saddle at the origin
and a center at 1,1.
import matplotlib.pyplot as plt
def plot_system(function, xmin, xmax, ymin, ymax, resolution):
 xnow = xmin
 i = 0
 while xnow < xmax:
 ynow = ymin
 while ynow < ymax:
 direction = function([xnow, ynow])
 if direction[0]**2 + direction[1]**2 != 0:
 scale = resolution / (direction[0]**2 + direction[1]**2)**.5
 print repr(direction[0] * scale) + ", " + repr(direction[1] * scale)
 plt.arrow(xnow, ynow, direction[0] * scale, direction[1] * scale)
 ynow = ynow + resolution
 xnow = xnow + resolution
 print "plotting"
 plt.show()
 
if __name__ == "__main__":
 def function(y):
 return [y[0] - y[0]*y[1], y[0]*y[1] - y[1]]
 
 plot_system(function, -10, 10, -10, 10, 1)
-- 
View this message in context: http://www.nabble.com/Arrows-acting-funny-tp20713470p20713470.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /