1
1
import matplotlib .pyplot as plt
2
+ from matplotlib .testing .decorators import check_figures_equal
2
3
from matplotview .tests .utils import plotting_test , matches_post_pickle
3
- from matplotview import view , view_wrapper , inset_zoom_axes
4
+ from matplotview import view , view_wrapper , inset_zoom_axes , DEFAULT_RENDER_DEPTH
4
5
import numpy as np
5
6
6
7
@@ -16,6 +17,48 @@ def test_obj_comparison():
16
17
assert view_class2 != view_class3
17
18
18
19
20
+ @check_figures_equal (tol = 5.6 )
21
+ def test_getters_and_setters (fig_test , fig_ref ):
22
+ np .random .seed (1 )
23
+ im_data1 = np .random .rand (30 , 30 )
24
+ im_data2 = np .random .rand (20 , 20 )
25
+
26
+ ax1 , ax2 , ax3 = fig_test .subplots (1 , 3 )
27
+ ax1 .imshow (im_data1 , origin = "lower" , interpolation = "nearest" )
28
+ ax2 .imshow (im_data2 , origin = "lower" , interpolation = "nearest" )
29
+ ax2 .plot ([i for i in range (10 )])
30
+ line = ax2 .plot ([i for i in range (10 , 0 , - 1 )])[0 ]
31
+ view (ax3 , ax1 )
32
+ ax3 .set_xlim (0 , 30 )
33
+ ax3 .set_ylim (0 , 30 )
34
+ ax3 .set_aspect (1 )
35
+
36
+ # Assert all getters return default or set values...
37
+ assert ax3 .get_axes_to_view () is ax1
38
+ assert ax3 .get_image_interpolation () == "nearest"
39
+ assert ax3 .get_max_render_depth () == DEFAULT_RENDER_DEPTH
40
+ assert ax3 .get_linescaling () == True
41
+ assert ax3 .get_filter_function () is None
42
+
43
+ # Attempt setting to different values...
44
+ ax3 .set_axes_to_view (ax2 )
45
+ # If this doesn't change pdf backend gets error > 5.6....
46
+ ax3 .set_image_interpolation ("bicubic" )
47
+ ax3 .set_max_render_depth (10 )
48
+ ax3 .set_linescaling (False )
49
+ ax3 .set_filter_function (lambda a : a != line )
50
+
51
+ # Compare against new thing...
52
+ ax1 , ax2 , ax3 = fig_ref .subplots (1 , 3 )
53
+ ax1 .imshow (im_data1 , origin = "lower" , interpolation = "nearest" )
54
+ ax2 .imshow (im_data2 , origin = "lower" , interpolation = "nearest" )
55
+ ax2 .plot ([i for i in range (10 )])
56
+ ax2 .plot ([i for i in range (10 , 0 , - 1 )])
57
+ ax3 .imshow (im_data2 , origin = "lower" , interpolation = "nearest" )
58
+ ax3 .plot ([i for i in range (10 )])
59
+ ax3 .set_xlim (0 , 30 )
60
+ ax3 .set_ylim (0 , 30 )
61
+
19
62
@plotting_test ()
20
63
def test_subplot_view_pickle (fig_test ):
21
64
np .random .seed (1 )
@@ -60,7 +103,6 @@ def test_zoom_plot_pickle(fig_test):
60
103
61
104
assert matches_post_pickle (fig_test )
62
105
63
-
64
106
@plotting_test ()
65
107
def test_3d_view_pickle (fig_test ):
66
108
X = Y = np .arange (- 5 , 5 , 0.25 )
0 commit comments