22import pytest
33from matplotlib import pyplot as plt
44
5- from tikzplotlib import get_tikz_code
6- from tikzplotlib import _cleanfigure as cleanfigure
5+ from tikzplotlib import clean_figure , get_tikz_code
76
87RC_PARAMS = {"figure.figsize" : [5 , 5 ], "figure.dpi" : 220 , "pgf.rcfonts" : False }
98
109
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-
8010class Test_plottypes :
8111 """Testing plot types found here https://matplotlib.org/3.1.1/tutorials/introductory/sample_plots.html"""
8212
@@ -91,7 +21,7 @@ def test_plot(self):
9121 ax .set_xlim ([20 , 80 ])
9222 raw = get_tikz_code ()
9323
94- cleanfigure . clean_figure (fig )
24+ clean_figure (fig )
9525 clean = get_tikz_code ()
9626
9727 # Use number of lines to test if it worked.
@@ -113,7 +43,7 @@ def test_step(self):
11343 ax .set_ylim ([20 , 80 ])
11444 ax .set_xlim ([20 , 80 ])
11545 with pytest .warns (Warning ):
116- cleanfigure . clean_figure (fig )
46+ clean_figure (fig )
11747 plt .close ("all" )
11848
11949 def test_scatter (self ):
@@ -127,7 +57,7 @@ def test_scatter(self):
12757 ax .set_xlim ([20 , 80 ])
12858 raw = get_tikz_code ()
12959
130- cleanfigure . clean_figure ()
60+ clean_figure ()
13161 clean = get_tikz_code ()
13262
13363 # Use number of lines to test if it worked.
@@ -148,7 +78,7 @@ def test_bar(self):
14878 ax .set_ylim ([20 , 80 ])
14979 ax .set_xlim ([20 , 80 ])
15080 with pytest .warns (Warning ):
151- cleanfigure . clean_figure (fig )
81+ clean_figure (fig )
15282 plt .close ("all" )
15383
15484 def test_hist (self ):
@@ -161,7 +91,7 @@ def test_hist(self):
16191 ax .set_ylim ([20 , 80 ])
16292 ax .set_xlim ([20 , 80 ])
16393 with pytest .warns (Warning ):
164- cleanfigure . clean_figure (fig )
94+ clean_figure (fig )
16595 plt .close ("all" )
16696
16797 def test_plot3d (self ):
@@ -181,7 +111,7 @@ def test_plot3d(self):
181111 ax .view_init (30 , 30 )
182112 raw = get_tikz_code (fig )
183113
184- cleanfigure . clean_figure (fig )
114+ clean_figure (fig )
185115 clean = get_tikz_code ()
186116
187117 # Use number of lines to test if it worked.
@@ -208,7 +138,7 @@ def test_scatter3d(self):
208138 ax .view_init (30 , 30 )
209139 raw = get_tikz_code (fig )
210140
211- cleanfigure . clean_figure (fig )
141+ clean_figure (fig )
212142 clean = get_tikz_code ()
213143
214144 # Use number of lines to test if it worked.
@@ -232,7 +162,7 @@ def test_wireframe3D(self):
232162 # Plot a basic wireframe.
233163 ax .plot_wireframe (X , Y , Z , rstride = 10 , cstride = 10 )
234164 with pytest .warns (Warning ):
235- cleanfigure . clean_figure (fig )
165+ clean_figure (fig )
236166 plt .close ("all" )
237167
238168 def test_surface3D (self ):
@@ -264,7 +194,7 @@ def test_surface3D(self):
264194 fig .colorbar (surf , shrink = 0.5 , aspect = 5 )
265195
266196 with pytest .warns (Warning ):
267- cleanfigure . clean_figure (fig )
197+ clean_figure (fig )
268198 plt .close ("all" )
269199
270200 def test_trisurface3D (self ):
@@ -297,7 +227,7 @@ def test_trisurface3D(self):
297227
298228 ax .plot_trisurf (x , y , z , linewidth = 0.2 , antialiased = True )
299229 with pytest .warns (Warning ):
300- cleanfigure . clean_figure (fig )
230+ clean_figure (fig )
301231 plt .close ("all" )
302232
303233 def test_contour3D (self ):
@@ -312,7 +242,7 @@ def test_contour3D(self):
312242 cset = ax .contour (X , Y , Z , cmap = cm .coolwarm )
313243 ax .clabel (cset , fontsize = 9 , inline = 1 )
314244 with pytest .warns (Warning ):
315- cleanfigure . clean_figure (fig )
245+ clean_figure (fig )
316246 plt .close ("all" )
317247
318248 def test_polygon3D (self ):
@@ -352,7 +282,7 @@ def cc(arg):
352282 ax .set_zlabel ("Z" )
353283 ax .set_zlim3d (0 , 1 )
354284 with pytest .warns (Warning ):
355- cleanfigure . clean_figure (fig )
285+ clean_figure (fig )
356286 plt .close ("all" )
357287
358288 def test_bar3D (self ):
@@ -376,7 +306,7 @@ def test_bar3D(self):
376306 ax .set_ylabel ("Y" )
377307 ax .set_zlabel ("Z" )
378308 with pytest .warns (Warning ):
379- cleanfigure . clean_figure (fig )
309+ clean_figure (fig )
380310 plt .close ("all" )
381311
382312 def test_quiver3D (self ):
@@ -406,7 +336,7 @@ def test_quiver3D(self):
406336
407337 ax .quiver (x , y , z , u , v , w , length = 0.1 , normalize = True )
408338 with pytest .warns (Warning ):
409- cleanfigure . clean_figure (fig )
339+ clean_figure (fig )
410340 plt .close ("all" )
411341
412342 def test_2D_in_3D (self ):
@@ -463,7 +393,7 @@ def test_line_no_markers(self):
463393 ax .set_xlim ([20 , 80 ])
464394 raw = get_tikz_code ()
465395
466- cleanfigure . clean_figure (fig )
396+ clean_figure (fig )
467397 clean = get_tikz_code ()
468398
469399 # Use number of lines to test if it worked.
@@ -489,7 +419,7 @@ def test_no_line_markers(self):
489419 ax .set_xlim ([20 , 80 ])
490420 raw = get_tikz_code ()
491421
492- cleanfigure . clean_figure (fig )
422+ clean_figure (fig )
493423 clean = get_tikz_code ()
494424
495425 # Use number of lines to test if it worked.
@@ -515,7 +445,7 @@ def test_line_markers(self):
515445 ax .set_xlim ([20 , 80 ])
516446 raw = get_tikz_code ()
517447
518- cleanfigure . clean_figure (fig )
448+ clean_figure (fig )
519449 clean = get_tikz_code ()
520450
521451 # Use number of lines to test if it worked.
@@ -538,7 +468,7 @@ def test_sine(self):
538468 ax .set_ylim ([- 1 , 1 ])
539469 raw = get_tikz_code ()
540470
541- cleanfigure . clean_figure (fig )
471+ clean_figure (fig )
542472 clean = get_tikz_code ()
543473
544474 # Use number of lines to test if it worked.
@@ -589,7 +519,7 @@ def test_subplot(self):
589519 ax .set_xlim ([20 , 80 ])
590520 raw = get_tikz_code ()
591521
592- cleanfigure . clean_figure (fig )
522+ clean_figure (fig )
593523 clean = get_tikz_code ()
594524
595525 # Use number of lines to test if it worked.
0 commit comments