File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 11
11
12
12
import imagehash
13
13
import matplotlib
14
+ import matplotlib .image as mpimg
14
15
import matplotlib .pyplot as plt
15
16
from PIL import Image
16
17
@@ -151,6 +152,30 @@ def get_details(self):
151
152
return
152
153
153
154
155
+ def compare_with_latex (fig ):
156
+
157
+ # Store original as PNG
158
+ _ , prefix = tempfile .mkstemp ()
159
+ filename = prefix + '.png'
160
+ plt .savefig (filename , bbox_inches = 'tight' )
161
+
162
+ # Get PNG of LaTeX conversion
163
+ obj = Phash (fig )
164
+
165
+ # Display both
166
+ plt .figure ()
167
+ plt .subplot (121 )
168
+ img0 = mpimg .imread (filename )
169
+ plt .imshow (img0 )
170
+ #
171
+ plt .subplot (122 )
172
+ img1 = mpimg .imread (obj .png_file )
173
+ plt .imshow (img1 )
174
+
175
+ plt .show ()
176
+ return
177
+
178
+
154
179
def print_tree (obj , indent = '' ):
155
180
'''Recursively prints the tree structure of the matplotlib object.
156
181
'''
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
#
3
- from helpers import Phash
3
+ import helpers
4
4
5
5
6
6
def plot ():
@@ -24,5 +24,9 @@ def plot():
24
24
25
25
26
26
def test ():
27
- phash = Phash (plot ())
27
+ phash = helpers . Phash (plot ())
28
28
assert phash .phash == '1f36e5c621c1e7c1' , phash .get_details ()
29
+
30
+
31
+ if __name__ == '__main__' :
32
+ helpers .compare_with_latex (plot ())
Original file line number Diff line number Diff line change @@ -33,3 +33,7 @@ def test():
33
33
phash = helpers .Phash (plot ())
34
34
assert phash .phash == '7f7ca18386d10eaa' , phash .get_details ()
35
35
return
36
+
37
+
38
+ if __name__ == '__main__' :
39
+ helpers .compare_with_latex (plot ())
You can’t perform that action at this time.
0 commit comments