TroglodyteDerivations commited on
Commit
a78f833
1 Parent(s): 5fb72ba

Modified the Object behavior / Method plot_vector_add into a previous instantiation

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -18,10 +18,10 @@ class Vector_Addition:
18
  v3_text = f'The new vector 3 produced = vector 1: {self.v1} + vector 2: {self.v2} = {v3}'
19
  return v3_text
20
 
21
- def plot_vector_add(self):
22
  plt.figure(figsize=(10,5))
23
  plt.plot([0, self.v1[0]], [0, self.v1[1]], 'b', label='v1')
24
- plt.plot([0, self.v2[0]+self.v1[0]], [0, self.v2[1]+self.v1[1]], 'r', label='v2')
25
  plt.plot([0, self.v1[0]+ self.v2[0]], [0, self.v1[1]+ self.v2[1]], 'k', label='v1+v2')
26
  plt.xlabel('X')
27
  plt.ylabel('Y')
@@ -36,6 +36,13 @@ class Vector_Addition:
36
  plt.close()
37
  return image
38
 
 
 
 
 
 
 
 
39
  def vector_addition(v1, v2):
40
  vector_addition = Vector_Addition(v1, v2)
41
  v3 = vector_addition.vector_add()
 
18
  v3_text = f'The new vector 3 produced = vector 1: {self.v1} + vector 2: {self.v2} = {v3}'
19
  return v3_text
20
 
21
+ def plot_vector_add(self):
22
  plt.figure(figsize=(10,5))
23
  plt.plot([0, self.v1[0]], [0, self.v1[1]], 'b', label='v1')
24
+ plt.plot([0, self.v2[0]], [0, self.v2[1]], 'r', label='v2')
25
  plt.plot([0, self.v1[0]+ self.v2[0]], [0, self.v1[1]+ self.v2[1]], 'k', label='v1+v2')
26
  plt.xlabel('X')
27
  plt.ylabel('Y')
 
36
  plt.close()
37
  return image
38
 
39
+ buf = BytesIO()
40
+ plt.savefig(buf, format='png')
41
+ buf.seek(0)
42
+ image = Image.open(buf)
43
+ plt.close()
44
+ return image
45
+
46
  def vector_addition(v1, v2):
47
  vector_addition = Vector_Addition(v1, v2)
48
  v3 = vector_addition.vector_add()