@@ -307,19 +307,28 @@ class Axes(Artist):
307
307
308
308
"""
309
309
310
+ scaled = {IDENTITY : 'linear' ,
311
+ LOG10 : 'log' ,
312
+ }
310
313
def __init__ (self , fig , rect ,
311
314
axisbg = None , # defaults to rc axes.facecolor
312
- frameon = True ):
315
+ frameon = True ,
316
+ sharex = None , # use Axes instance's xaxis info
317
+ sharey = None , # use Axes instance's yaxis info
318
+ ):
313
319
Artist .__init__ (self )
314
320
self ._position = map (makeValue , rect )
321
+ # must be set before set_figure
322
+ self ._sharex = sharex # I use sharex's
323
+ self ._sharey = sharey
324
+
325
+
315
326
self .set_figure (fig )
316
327
317
328
if axisbg is None : axisbg = rcParams ['axes.facecolor' ]
318
329
self ._axisbg = axisbg
319
330
self ._frameon = frameon
320
- self ._xscale = 'linear'
321
- self ._yscale = 'linear'
322
-
331
+
323
332
324
333
self ._hold = rcParams ['axes.hold' ]
325
334
self ._connected = {} # a dict from events to (id, func)
@@ -360,11 +369,33 @@ def _set_lim_and_transforms(self):
360
369
set the dataLim and viewLim BBox attributes and the
361
370
transData and transAxes Transformation attributes
362
371
"""
372
+
373
+
374
+ if self ._sharex is not None :
375
+ left = self ._sharex .viewLim .ll ().x ()
376
+ right = self ._sharex .viewLim .ur ().x ()
377
+ else :
378
+ left = zero ()
379
+ right = one ()
380
+ if self ._sharey is not None :
381
+ bottom = self ._sharey .viewLim .ll ().y ()
382
+ top = self ._sharey .viewLim .ur ().y ()
383
+ else :
384
+ bottom = zero ()
385
+ top = one ()
386
+
387
+ self .viewLim = Bbox (Point (left , bottom ), Point (right , top ))
363
388
self .dataLim = unit_bbox ()
364
- self .viewLim = unit_bbox ()
389
+
390
+
365
391
self .transData = get_bbox_transform (self .viewLim , self .bbox )
366
392
self .transAxes = get_bbox_transform (unit_bbox (), self .bbox )
367
393
394
+ if self ._sharex :
395
+ self .transData .set_funcx (self ._sharex .transData .get_funcx ())
396
+
397
+ if self ._sharey :
398
+ self .transData .set_funcy (self ._sharey .transData .get_funcy ())
368
399
369
400
def axhline (self , y = 0 , xmin = 0 , xmax = 1 , ** kwargs ):
370
401
"""\
@@ -569,12 +600,19 @@ def _set_artist_props(self, a):
569
600
def cla (self ):
570
601
'Clear the current axes'
571
602
572
- # init these w/ some arbitrary numbers - they'll be updated as
573
- # data is added to the axes
574
603
604
+ # TODO: don't recreate x and y axis instances on cla, simply
605
+ # clear them
575
606
self .xaxis = XAxis (self )
576
607
self .yaxis = YAxis (self )
577
608
609
+ if self ._sharex is not None :
610
+ self .xaxis ._major = self ._sharex .xaxis ._major
611
+ self .xaxis ._minor = self ._sharex .xaxis ._minor
612
+ if self ._sharey is not None :
613
+ self .yaxis ._major = self ._sharey .yaxis ._major
614
+ self .yaxis ._minor = self ._sharey .yaxis ._minor
615
+
578
616
self ._get_lines = _process_plot_var_args ()
579
617
self ._get_patches_for_fill = _process_plot_var_args ('fill' )
580
618
@@ -628,11 +666,11 @@ def get_images(self):
628
666
629
667
def get_xscale (self ):
630
668
'return the xaxis scale string: log or linear'
631
- return self ._xscale
669
+ return self .scaled [ self . transData . get_funcx (). get_type ()]
632
670
633
671
def get_yscale (self ):
634
672
'return the yaxis scale string: log or linear'
635
- return self ._yscale
673
+ return self .scaled [ self . transData . get_funcy (). get_type ()]
636
674
637
675
def update_datalim (self , xys ):
638
676
'Update the data lim bbox with seq of xy tups'
@@ -2754,17 +2792,17 @@ def set_xscale(self, value, basex = 10, subsx=None):
2754
2792
2755
2793
if subsx is None : subsx = range (2 , basex )
2756
2794
assert (value .lower () in ('log' , 'linear' , ))
2757
- self ._xscale = value
2758
2795
if value == 'log' :
2759
2796
self .xaxis .set_major_locator (LogLocator (basex ))
2760
2797
self .xaxis .set_major_formatter (LogFormatterMathtext (basex ))
2761
2798
self .xaxis .set_minor_locator (LogLocator (basex ,subsx ))
2799
+
2762
2800
self .transData .get_funcx ().set_type (LOG10 )
2763
2801
elif value == 'linear' :
2764
2802
self .xaxis .set_major_locator (AutoLocator ())
2765
2803
self .xaxis .set_major_formatter (ScalarFormatter ())
2766
2804
self .transData .get_funcx ().set_type ( IDENTITY )
2767
-
2805
+
2768
2806
2769
2807
def set_xticklabels (self , labels , fontdict = None , ** kwargs ):
2770
2808
"""\
@@ -2833,7 +2871,7 @@ def set_yscale(self, value, basey=10, subsy=None):
2833
2871
2834
2872
if subsy is None : subsy = range (2 , basey )
2835
2873
assert (value .lower () in ('log' , 'linear' , ))
2836
- self . _yscale = value
2874
+
2837
2875
if value == 'log' :
2838
2876
self .yaxis .set_major_locator (LogLocator (basey ))
2839
2877
self .yaxis .set_major_formatter (LogFormatterMathtext (basey ))
@@ -2844,8 +2882,6 @@ def set_yscale(self, value, basey=10, subsy=None):
2844
2882
self .yaxis .set_major_formatter (ScalarFormatter ())
2845
2883
self .transData .get_funcy ().set_type ( IDENTITY )
2846
2884
2847
-
2848
-
2849
2885
def set_yticklabels (self , labels , fontdict = None , ** kwargs ):
2850
2886
"""\
2851
2887
SET_YTICKLABELS(labels, fontdict=None, **kwargs)
@@ -3627,6 +3663,15 @@ def set_xlabel(self, xlabel, fontdict=None, **kwargs):
3627
3663
def set_ylabel (self , ylabel , fontdict = None , ** kwargs ):
3628
3664
'ylabel not implemented'
3629
3665
raise NotImplementedError ('ylabel not defined for polar axes (yet)' )
3666
+
3667
+
3668
+ def get_xscale (self ):
3669
+ 'return the xaxis scale string'
3670
+ return 'polar'
3671
+
3672
+ def get_yscale (self ):
3673
+ 'return the yaxis scale string'
3674
+ return 'polar'
3630
3675
3631
3676
class PolarSubplot (SubplotBase , PolarAxes ):
3632
3677
"""
@@ -3646,45 +3691,3 @@ def __init__(self, fig, *args, **kwargs):
3646
3691
SubplotBase .__init__ (self , * args )
3647
3692
PolarAxes .__init__ (self , fig , [self .figLeft , self .figBottom , self .figW , self .figH ], ** kwargs )
3648
3693
3649
- class TwinAxes (Axes ):
3650
- """
3651
- Create an Axes instance that shares the X axis with another:
3652
-
3653
- TwinAxes(existing_axes)
3654
- """
3655
- def __init__ (self , axes ):
3656
- Axes .__init__ (self , axes .figure , axes ._position , frameon = False )
3657
-
3658
- self ._xscale = axes ._xscale
3659
- self .fmt_xdata = axes .fmt_xdata
3660
-
3661
- vl_left = axes .viewLim .ll ().x ()
3662
- vl_right = axes .viewLim .ur ().x ()
3663
- vl_bottom = self .viewLim .ll ().y ()
3664
- vl_top = self .viewLim .ur ().y ()
3665
- self .viewLim = Bbox (Point (vl_left ,vl_bottom ),Point (vl_right , vl_top ))
3666
-
3667
- dl_left = axes .dataLim .ll ().x ()
3668
- dl_right = axes .dataLim .ur ().x ()
3669
- dl_bottom = self .dataLim .ll ().y ()
3670
- dl_top = self .dataLim .ur ().y ()
3671
- self .dataLim = Bbox (Point (dl_left ,dl_bottom ),Point (dl_right , dl_top ))
3672
-
3673
- try :
3674
- self .transData = blend_xy_sep_transform (axes .transData , self .transData )
3675
- except RuntimeError :
3676
- raise RuntimeError , "TwinAxes only works with cartesian axes"
3677
-
3678
- self .xaxis = axes .xaxis
3679
-
3680
- self .yaxis .tick_right ()
3681
- self .yaxis .set_label_position ('right' )
3682
- axes .yaxis .tick_left ()
3683
-
3684
- def set_figure (self , fig ):
3685
- if self .figure is None :
3686
- Axes .set_figure (self , fig )
3687
- return None
3688
- if fig is not self .figure :
3689
- raise RuntimeError , "TwinAxes can only be added to the same figure"
3690
-
0 commit comments