In the following code, a,b,c represent three expressions: 10x+7y=200, 11x-8y=63, and x+y=42. I would like to graph each of these expressions and I'm not sure what the best way to go about it is.
When I yield the following code:
import matplotlib.pyplot as plt
#Set minimum graph boundary
xMin = 0
yMin = 0
#a,b,c variables pulled from multiple expressions (ax+by=c)
a = [10,11,1]
b = [7,-8,1]
c = [200,63,42]
def init():
#Create x,y lists // These will contain x,y plots
x = []
y = []
def findxy(a,b,c):
#Analyzes instances of (ax+by=c) and returns x,y; appends them to lists
#Finds x,y for ax+by=c
x.append((-b*yMin)/a + c/a)
y.append((-a*xMin)/b + c/b)
def printxy(x,y):
#Prints results of findxy, followed by "z = 15x + 15y"
if x >= xMin:
print '(%s, %s)' % (x,yMin), 15 * x + 15 * yMin
if y >= yMin:
print '(%s, %s)' % (xMin,y), 15 * xMin + 15 * y
map(findxy,a,b,c)
map(printxy,x,y)
plt.plot(x,y)
plt.show()
... I get the following result:
>>>
(20, 0) 300
(0, 28) 420
(5, 0) 75
(42, 0) 630
(0, 42) 630
... where (20,0),(0,28) represent the first expression, 10x+7y=200; (5,0) represents the second expression, omitting one ordered pair because it violates the x≥0 condition (although appending it to x,y, respectively), and (42,0),(0,42) represent the final expression.
How can I convert each of these expressions to its own line to be printed with matplotlib? I've considered creating a new list, line[], that each pass through findxy() will append x,y to line[n+1], but I'm not certain if that's a good way to go.