11import matplotlib .pyplot as plt
2+ from matplotlib .testing .decorators import check_figures_equal
23from 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
45import numpy as np
56
67
@@ -16,6 +17,48 @@ def test_obj_comparison():
1617 assert view_class2 != view_class3
1718
1819
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+
1962@plotting_test ()
2063def test_subplot_view_pickle (fig_test ):
2164 np .random .seed (1 )
@@ -60,7 +103,6 @@ def test_zoom_plot_pickle(fig_test):
60103
61104 assert matches_post_pickle (fig_test )
62105
63-
64106@plotting_test ()
65107def test_3d_view_pickle (fig_test ):
66108 X = Y = np .arange (- 5 , 5 , 0.25 )
0 commit comments