File tree Expand file tree Collapse file tree 5 files changed +69
-2
lines changed Expand file tree Collapse file tree 5 files changed +69
-2
lines changed Original file line number Diff line number Diff line change 1
1
tex /
2
+ zzz_readme_test.py
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
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ import helpers
4
+
5
+
6
+ def plot ():
7
+ from matplotlib import pyplot as plt
8
+ import numpy as np
9
+
10
+ fig = plt .figure ()
11
+
12
+ x = np .ma .arange (0 , 2 * np .pi , 0.02 )
13
+ y1 = np .sin (1 * x )
14
+ y2 = np .sin (2 * x )
15
+ y3 = np .sin (3 * x )
16
+
17
+ plt .plot (x , y1 , label = 'y1' )
18
+ plt .plot (x , y2 , label = None )
19
+ plt .plot (x , y3 , label = 'y4' )
20
+ plt .legend ()
21
+
22
+ return fig
23
+
24
+
25
+ def test ():
26
+ phash = helpers .Phash (plot ())
27
+ assert phash .phash == 'fb7c5e0aaed60094' , phash .get_details ()
28
+ return
29
+
30
+
31
+ if __name__ == '__main__' :
32
+ # print(helpers.Phash(plot()).phash)
33
+ 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