@@ -272,16 +272,14 @@ def test_polar_wrap():
272
272
273
273
fig = plt .figure ()
274
274
275
- #NOTE: resolution=1 really should be the default
276
- plt .subplot ( 111 , polar = True , resolution = 1 )
275
+ plt .subplot (111 , polar = True )
277
276
plt .polar ( [179 * D2R , - 179 * D2R ], [0.2 , 0.1 ], "b.-" )
278
277
plt .polar ( [179 * D2R , 181 * D2R ], [0.2 , 0.1 ], "g.-" )
279
278
plt .rgrids ( [0.05 , 0.1 , 0.15 , 0.2 , 0.25 , 0.3 ] )
280
279
281
280
fig = plt .figure ()
282
281
283
- #NOTE: resolution=1 really should be the default
284
- plt .subplot ( 111 , polar = True , resolution = 1 )
282
+ plt .subplot ( 111 , polar = True )
285
283
plt .polar ( [2 * D2R , - 2 * D2R ], [0.2 , 0.1 ], "b.-" )
286
284
plt .polar ( [2 * D2R , 358 * D2R ], [0.2 , 0.1 ], "g.-" )
287
285
plt .polar ( [358 * D2R , 2 * D2R ], [0.2 , 0.1 ], "r.-" )
@@ -713,6 +711,56 @@ def test_scatter_plot():
713
711
ax .scatter ([3 , 4 , 2 , 6 ], [2 , 5 , 2 , 3 ], c = ['r' , 'y' , 'b' , 'lime' ], s = [24 , 15 , 19 , 29 ])
714
712
715
713
714
+ def test_as_mpl_axes_api ():
715
+ # tests the _as_mpl_axes api
716
+ from matplotlib .projections .polar import PolarAxes
717
+ import matplotlib .axes as maxes
718
+
719
+ class Polar (object ):
720
+ def __init__ (self ):
721
+ self .theta_offset = 0
722
+
723
+ def _as_mpl_axes (self ):
724
+ # implement the matplotlib axes interface
725
+ return PolarAxes , {'theta_offset' : self .theta_offset }
726
+ prj = Polar ()
727
+ prj2 = Polar ()
728
+ prj2 .theta_offset = np .pi
729
+ prj3 = Polar ()
730
+
731
+ # testing axes creation with plt.axes
732
+ ax = plt .axes ([0 , 0 , 1 , 1 ], projection = prj )
733
+ assert type (ax ) == PolarAxes , \
734
+ 'Expected a PolarAxes, got %s' % type (ax )
735
+ ax_via_gca = plt .gca (projection = prj )
736
+ # ideally, ax_via_gca is ax should be true. However, gca isn't
737
+ # plummed like that. (even with projection='polar').
738
+ assert ax_via_gca is not ax
739
+ plt .close ()
740
+
741
+ # testing axes creation with gca
742
+ ax = plt .gca (projection = prj )
743
+ assert type (ax ) == maxes ._subplot_classes [PolarAxes ], \
744
+ 'Expected a PolarAxesSubplot, got %s' % type (ax )
745
+ ax_via_gca = plt .gca (projection = prj )
746
+ assert ax_via_gca is ax
747
+ # try getting the axes given a different polar projection
748
+ ax_via_gca = plt .gca (projection = prj2 )
749
+ assert ax_via_gca is not ax
750
+ assert ax .get_theta_offset () == 0 , ax .get_theta_offset ()
751
+ assert ax_via_gca .get_theta_offset () == np .pi , ax_via_gca .get_theta_offset ()
752
+ # try getting the axes given an == (not is) polar projection
753
+ ax_via_gca = plt .gca (projection = prj3 )
754
+ assert ax_via_gca is ax
755
+ plt .close ()
756
+
757
+ # testing axes creation with subplot
758
+ ax = plt .subplot (121 , projection = prj )
759
+ assert type (ax ) == maxes ._subplot_classes [PolarAxes ], \
760
+ 'Expected a PolarAxesSubplot, got %s' % type (ax )
761
+ plt .close ()
762
+
763
+
716
764
if __name__ == '__main__' :
717
765
import nose
718
766
nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
0 commit comments