2
2
import pytest
3
3
from matplotlib import pyplot as plt
4
4
5
- from tikzplotlib import get_tikz_code
6
- from tikzplotlib import _cleanfigure as cleanfigure
5
+ from tikzplotlib import clean_figure , get_tikz_code
7
6
8
7
RC_PARAMS = {"figure.figsize" : [5 , 5 ], "figure.dpi" : 220 , "pgf.rcfonts" : False }
9
8
10
9
11
- class Test_pruneOutsideBox :
12
- def test_pruneOutsideBox2D (self ):
13
- """test against matlab2tikz implementation
14
-
15
- octave code to generate baseline results.
16
- Note that octave has indexing 1...N, whereas python has indexing 0...N-1.
17
- ```octave
18
- x = linspace(1, 100, 20);
19
- y1 = linspace(1, 100, 20);
20
-
21
- figure
22
- plot(x, y1)
23
- xlim([20, 80])
24
- ylim([20, 80])
25
- cleanfigure;
26
- ```
27
- """
28
- x = np .linspace (1 , 100 , 20 )
29
- y = np .linspace (1 , 100 , 20 )
30
-
31
- with plt .rc_context (rc = RC_PARAMS ):
32
- fig , ax = plt .subplots (1 , 1 , figsize = (5 , 5 ))
33
- (l ,) = ax .plot (x , y )
34
- ax .set_ylim ([20 , 80 ])
35
- ax .set_xlim ([20 , 80 ])
36
- axhandle = ax
37
- linehandle = l
38
- fighandle = fig
39
- data , is3D = cleanfigure ._get_line_data (linehandle )
40
- xLim , yLim = cleanfigure ._get_visual_limits (fighandle , axhandle )
41
- visual_data = cleanfigure ._get_visual_data (axhandle , data , is3D )
42
- hasLines = cleanfigure ._line_has_lines (linehandle )
43
-
44
- data = cleanfigure ._prune_outside_box (
45
- xLim , yLim , data , visual_data , is3D , hasLines
46
- )
47
- assert data .shape == (14 , 2 )
48
-
49
- def test_pruneOutsideBox3D (self ):
50
- theta = np .linspace (- 4 * np .pi , 4 * np .pi , 100 )
51
- z = np .linspace (- 2 , 2 , 100 )
52
- r = z ** 2 + 1
53
- x = r * np .sin (theta )
54
- y = r * np .cos (theta )
55
-
56
- with plt .rc_context (rc = RC_PARAMS ):
57
- fig = plt .figure ()
58
- ax = fig .add_subplot (111 , projection = "3d" )
59
- (l ,) = ax .plot (x , y , z )
60
- ax .set_xlim ([- 2 , 2 ])
61
- ax .set_ylim ([- 2 , 2 ])
62
- ax .set_zlim ([- 2 , 2 ])
63
- ax .view_init (30 , 30 )
64
-
65
- axhandle = ax
66
- linehandle = l
67
- fighandle = fig
68
- data , is3D = cleanfigure ._get_line_data (linehandle )
69
- xLim , yLim = cleanfigure ._get_visual_limits (fighandle , axhandle )
70
- visual_data = cleanfigure ._get_visual_data (axhandle , data , is3D )
71
- hasLines = cleanfigure ._line_has_lines (linehandle )
72
-
73
- data = cleanfigure ._prune_outside_box (
74
- xLim , yLim , data , visual_data , is3D , hasLines
75
- )
76
- assert data .shape == (86 , 3 )
77
- plt .close ("all" )
78
-
79
-
80
10
class Test_plottypes :
81
11
"""Testing plot types found here https://matplotlib.org/3.1.1/tutorials/introductory/sample_plots.html"""
82
12
@@ -91,7 +21,7 @@ def test_plot(self):
91
21
ax .set_xlim ([20 , 80 ])
92
22
raw = get_tikz_code ()
93
23
94
- cleanfigure . clean_figure (fig )
24
+ clean_figure (fig )
95
25
clean = get_tikz_code ()
96
26
97
27
# Use number of lines to test if it worked.
@@ -113,7 +43,7 @@ def test_step(self):
113
43
ax .set_ylim ([20 , 80 ])
114
44
ax .set_xlim ([20 , 80 ])
115
45
with pytest .warns (Warning ):
116
- cleanfigure . clean_figure (fig )
46
+ clean_figure (fig )
117
47
plt .close ("all" )
118
48
119
49
def test_scatter (self ):
@@ -127,7 +57,7 @@ def test_scatter(self):
127
57
ax .set_xlim ([20 , 80 ])
128
58
raw = get_tikz_code ()
129
59
130
- cleanfigure . clean_figure ()
60
+ clean_figure ()
131
61
clean = get_tikz_code ()
132
62
133
63
# Use number of lines to test if it worked.
@@ -148,7 +78,7 @@ def test_bar(self):
148
78
ax .set_ylim ([20 , 80 ])
149
79
ax .set_xlim ([20 , 80 ])
150
80
with pytest .warns (Warning ):
151
- cleanfigure . clean_figure (fig )
81
+ clean_figure (fig )
152
82
plt .close ("all" )
153
83
154
84
def test_hist (self ):
@@ -161,7 +91,7 @@ def test_hist(self):
161
91
ax .set_ylim ([20 , 80 ])
162
92
ax .set_xlim ([20 , 80 ])
163
93
with pytest .warns (Warning ):
164
- cleanfigure . clean_figure (fig )
94
+ clean_figure (fig )
165
95
plt .close ("all" )
166
96
167
97
def test_plot3d (self ):
@@ -181,7 +111,7 @@ def test_plot3d(self):
181
111
ax .view_init (30 , 30 )
182
112
raw = get_tikz_code (fig )
183
113
184
- cleanfigure . clean_figure (fig )
114
+ clean_figure (fig )
185
115
clean = get_tikz_code ()
186
116
187
117
# Use number of lines to test if it worked.
@@ -208,7 +138,7 @@ def test_scatter3d(self):
208
138
ax .view_init (30 , 30 )
209
139
raw = get_tikz_code (fig )
210
140
211
- cleanfigure . clean_figure (fig )
141
+ clean_figure (fig )
212
142
clean = get_tikz_code ()
213
143
214
144
# Use number of lines to test if it worked.
@@ -232,7 +162,7 @@ def test_wireframe3D(self):
232
162
# Plot a basic wireframe.
233
163
ax .plot_wireframe (X , Y , Z , rstride = 10 , cstride = 10 )
234
164
with pytest .warns (Warning ):
235
- cleanfigure . clean_figure (fig )
165
+ clean_figure (fig )
236
166
plt .close ("all" )
237
167
238
168
def test_surface3D (self ):
@@ -264,7 +194,7 @@ def test_surface3D(self):
264
194
fig .colorbar (surf , shrink = 0.5 , aspect = 5 )
265
195
266
196
with pytest .warns (Warning ):
267
- cleanfigure . clean_figure (fig )
197
+ clean_figure (fig )
268
198
plt .close ("all" )
269
199
270
200
def test_trisurface3D (self ):
@@ -297,7 +227,7 @@ def test_trisurface3D(self):
297
227
298
228
ax .plot_trisurf (x , y , z , linewidth = 0.2 , antialiased = True )
299
229
with pytest .warns (Warning ):
300
- cleanfigure . clean_figure (fig )
230
+ clean_figure (fig )
301
231
plt .close ("all" )
302
232
303
233
def test_contour3D (self ):
@@ -312,7 +242,7 @@ def test_contour3D(self):
312
242
cset = ax .contour (X , Y , Z , cmap = cm .coolwarm )
313
243
ax .clabel (cset , fontsize = 9 , inline = 1 )
314
244
with pytest .warns (Warning ):
315
- cleanfigure . clean_figure (fig )
245
+ clean_figure (fig )
316
246
plt .close ("all" )
317
247
318
248
def test_polygon3D (self ):
@@ -352,7 +282,7 @@ def cc(arg):
352
282
ax .set_zlabel ("Z" )
353
283
ax .set_zlim3d (0 , 1 )
354
284
with pytest .warns (Warning ):
355
- cleanfigure . clean_figure (fig )
285
+ clean_figure (fig )
356
286
plt .close ("all" )
357
287
358
288
def test_bar3D (self ):
@@ -376,7 +306,7 @@ def test_bar3D(self):
376
306
ax .set_ylabel ("Y" )
377
307
ax .set_zlabel ("Z" )
378
308
with pytest .warns (Warning ):
379
- cleanfigure . clean_figure (fig )
309
+ clean_figure (fig )
380
310
plt .close ("all" )
381
311
382
312
def test_quiver3D (self ):
@@ -406,7 +336,7 @@ def test_quiver3D(self):
406
336
407
337
ax .quiver (x , y , z , u , v , w , length = 0.1 , normalize = True )
408
338
with pytest .warns (Warning ):
409
- cleanfigure . clean_figure (fig )
339
+ clean_figure (fig )
410
340
plt .close ("all" )
411
341
412
342
def test_2D_in_3D (self ):
@@ -463,7 +393,7 @@ def test_line_no_markers(self):
463
393
ax .set_xlim ([20 , 80 ])
464
394
raw = get_tikz_code ()
465
395
466
- cleanfigure . clean_figure (fig )
396
+ clean_figure (fig )
467
397
clean = get_tikz_code ()
468
398
469
399
# Use number of lines to test if it worked.
@@ -489,7 +419,7 @@ def test_no_line_markers(self):
489
419
ax .set_xlim ([20 , 80 ])
490
420
raw = get_tikz_code ()
491
421
492
- cleanfigure . clean_figure (fig )
422
+ clean_figure (fig )
493
423
clean = get_tikz_code ()
494
424
495
425
# Use number of lines to test if it worked.
@@ -515,7 +445,7 @@ def test_line_markers(self):
515
445
ax .set_xlim ([20 , 80 ])
516
446
raw = get_tikz_code ()
517
447
518
- cleanfigure . clean_figure (fig )
448
+ clean_figure (fig )
519
449
clean = get_tikz_code ()
520
450
521
451
# Use number of lines to test if it worked.
@@ -538,7 +468,7 @@ def test_sine(self):
538
468
ax .set_ylim ([- 1 , 1 ])
539
469
raw = get_tikz_code ()
540
470
541
- cleanfigure . clean_figure (fig )
471
+ clean_figure (fig )
542
472
clean = get_tikz_code ()
543
473
544
474
# Use number of lines to test if it worked.
@@ -589,7 +519,7 @@ def test_subplot(self):
589
519
ax .set_xlim ([20 , 80 ])
590
520
raw = get_tikz_code ()
591
521
592
- cleanfigure . clean_figure (fig )
522
+ clean_figure (fig )
593
523
clean = get_tikz_code ()
594
524
595
525
# Use number of lines to test if it worked.
0 commit comments