diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2024-06-08 17:01:35 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2024-06-08 17:01:35 +0530 |
commit | fd9a31f983ef2cfd5c1a89be25fa9e262082737b (patch) | |
tree | 39371e157a3749ea824d211e315352963318122f | |
parent | 22f6c7e5b3fd45480f2ef7827474fdb9d6c6f82c (diff) |
Matplotlib -> Tkinter
Diffstat (limited to '')
-rwxr-xr-x | example.py | 33 | ||||
-rw-r--r-- | src/graph.py | 17 |
2 files changed, 43 insertions, 7 deletions
@@ -1,7 +1,35 @@ #!/usr/bin/env python from src.scalar import Scalar -from src.graph import Graph + +h = 0.0001 + +# def one(): +# a = Scalar(2, label='a') +# b = Scalar(-3, label='b') +# c = Scalar(10, label='c') +# f = Scalar(-2, label='f') +# +# d = a * b; d.label = 'd' +# e = d + c; e.label = 'e' +# L = e * f; L.label = 'L' +# +# return L.data +# +# def two(): +# a = Scalar(2, label='a') +# b = Scalar(-3, label='b') +# c = Scalar(10, label='c') +# f = Scalar(-2, label='f') +# +# d = a * b; d.label = 'd' +# d.data += h +# e = d + c; e.label = 'e' +# L = e * f; L.label = 'L' +# +# return L.data +# +# print((two() - one()) / h) a = Scalar(2, label='a') b = Scalar(-3, label='b') @@ -15,5 +43,8 @@ L = e * f; L.label = 'L' L.grad = 1.0 e.grad = -2.0 f.grad = 4.0 +d.grad = -2.0 +c.grad = -2.0 +from src.graph import Graph Graph(L).show() diff --git a/src/graph.py b/src/graph.py index 9aecde1..6c8ab53 100644 --- a/src/graph.py +++ b/src/graph.py @@ -1,4 +1,4 @@ -import io +import tkinter as tk from graphviz import Digraph import matplotlib.pyplot as plt @@ -49,8 +49,13 @@ class Graph: self.dot.edge(str(id(node1)), str(id(node2)) + node2._op) def show(self): - fp = io.BytesIO(self.dot.pipe(format='jpeg')) - with fp: - img = mpimg.imread(fp, format='jpeg') - plt.imshow(img) - plt.show() + root = tk.Tk() + root.title('float') + + data = self.dot.pipe(format='png') + img = tk.PhotoImage(data=data, format='png') + + panel = tk.Label(root, image=img) + panel.pack(); + + tk.mainloop() |