@@ -438,6 +438,7 @@ class Axis(Artist):
438438
439439 """
440440 LABELPAD = 5
441+ OFFSETTEXTPAD = 3
441442
442443 def __init__ (self , axes ):
443444 """
@@ -456,25 +457,9 @@ def __init__(self, axes):
456457 #self.minor = dummy()
457458
458459 self .label = self ._get_label ()
460+ self .offsetText = self ._get_offset_text ()
459461 self .majorTicks = []
460462 self .minorTicks = []
461-
462- if self .__name__ == 'xaxis' :
463- ox ,oy = 1 , - 0.06
464- v ,h = 'top' ,'right'
465- else :
466- ox ,oy = 0 , 1.01
467- v ,h = 'bottom' ,'left'
468- self .offsetText = Text (x = ox , y = oy ,
469- fontproperties = FontProperties (size = rcParams ['tick.labelsize' ]),
470- color = rcParams ['axes.labelcolor' ],
471- verticalalignment = v ,
472- horizontalalignment = h ,
473- )
474- self .offsetText .set_transform (self .axes .transAxes )
475- ## self.offsetText.set_transform( blend_xy_sep_transform( self.axes.transAxes,
476- ## identity_transform() ))
477- self ._set_artist_props (self .offsetText )
478463
479464 self .cla ()
480465
@@ -564,16 +549,17 @@ def draw(self, renderer, *args, **kwargs):
564549 if tick .label2On :
565550 extent = tick .label2 .get_window_extent (renderer )
566551 ticklabelBoxes2 .append (extent )
567-
568- self .offsetText .set_text ( self .major .formatter .get_offset () )
569- self .offsetText .draw (renderer )
570552
571553 # scale up the axis label box to also find the neighbors, not
572554 # just the tick labels that actually overlap note we need a
573555 # *copy* of the axis label box because we don't wan't to scale
574556 # the actual bbox
575- self ._update_label_postion (ticklabelBoxes , ticklabelBoxes2 )
557+ self ._update_label_position (ticklabelBoxes , ticklabelBoxes2 )
576558 self .label .draw (renderer ) # memory leak here, vertical text
559+
560+ self ._update_offset_text_position (ticklabelBoxes , ticklabelBoxes2 )
561+ self .offsetText .set_text ( self .major .formatter .get_offset () )
562+ self .offsetText .draw (renderer )
577563
578564 if 0 : # draw the bounding boxes around the text for debug
579565 for tick in majorTicks :
@@ -585,14 +571,21 @@ def draw(self, renderer, *args, **kwargs):
585571
586572 def _get_label (self ):
587573 raise NotImplementedError ('Derived must override' )
574+
575+ def _get_offset_text (self ):
576+ raise NotImplementedError ('Derived must override' )
588577
589578 def get_gridlines (self ):
590579 'Return the grid lines as a list of Line2D instance'
591580 return silent_list ('Line2D gridline' , [tick .gridline for tick in self .majorTicks ])
592581
593582 def get_label (self ):
594- 'Return the axis label as an Text instance'
583+ 'Return the axis label as a Text instance'
595584 return self .label
585+
586+ def get_offset_text (self ):
587+ 'Return the axis offsetText as a Text instance'
588+ return self .offsetText
596589
597590 def get_ticklabels (self ):
598591 'Return a list of Text instances for ticklabels'
@@ -768,7 +761,14 @@ def set_ticks(self, ticks):
768761 self .get_view_interval ().update (ticks ,0 )
769762 return self .get_major_ticks ()
770763
771- def _update_label_postion (self , bboxes ):
764+ def _update_label_position (self , bboxes , bboxes2 ):
765+ """
766+ Update the label position based on the sequence of bounding
767+ boxes of all the ticklabels
768+ """
769+ raise NotImplementedError ('Derived must override' )
770+
771+ def _update_offset_text_postion (self , bboxes , bboxes2 ):
772772 """
773773 Update the label position based on the sequence of bounding
774774 boxes of all the ticklabels
@@ -791,7 +791,7 @@ def _get_tick(self, major):
791791
792792 def _get_label (self ):
793793 # x in axes coords, y in display coords (to be updated at draw
794- # time by _update_label_positions
794+ # time by _update_label_positions)
795795 label = Text (x = 0.5 , y = 0 ,
796796 fontproperties = FontProperties (size = rcParams ['axes.labelsize' ]),
797797 color = rcParams ['axes.labelcolor' ],
@@ -804,6 +804,20 @@ def _get_label(self):
804804 self ._set_artist_props (label )
805805 self .label_position = 'bottom'
806806 return label
807+
808+ def _get_offset_text (self ):
809+ # x in axes coords, y in display coords (to be updated at draw time)
810+ offsetText = Text (x = 1 , y = 0 ,
811+ fontproperties = FontProperties (size = rcParams ['tick.labelsize' ]),
812+ color = rcParams ['tick.color' ],
813+ verticalalignment = 'top' ,
814+ horizontalalignment = 'right' ,
815+ )
816+ offsetText .set_transform ( blend_xy_sep_transform ( self .axes .transAxes ,
817+ identity_transform () ))
818+ self ._set_artist_props (offsetText )
819+ self .offset_text_position = 'bottom'
820+ return offsetText
807821
808822 def get_label_position (self ):
809823 """
@@ -824,7 +838,7 @@ def set_label_position(self, position):
824838 self .label .set_verticalalignment ('top' )
825839 self .label_position = position
826840
827- def _update_label_postion (self , bboxes , bboxes2 ):
841+ def _update_label_position (self , bboxes , bboxes2 ):
828842 """
829843 Update the label position based on the sequence of bounding
830844 boxes of all the ticklabels
@@ -850,6 +864,19 @@ def _update_label_postion(self, bboxes, bboxes2):
850864 top = bbox .ymax ()
851865
852866 self .label .set_position ( (x , top + self .LABELPAD * self .figure .dpi .get ()/ 72.0 ))
867+
868+ def _update_offset_text_position (self , bboxes , bboxes2 ):
869+ """
870+ Update the offset_text position based on the sequence of bounding
871+ boxes of all the ticklabels
872+ """
873+ x ,y = self .offsetText .get_position ()
874+ if not len (bboxes ):
875+ bottom = self .axes .bbox .ymin ()
876+ else :
877+ bbox = bbox_all (bboxes )
878+ bottom = bbox .ymin ()
879+ self .offsetText .set_position ((x , bottom - self .OFFSETTEXTPAD * self .figure .dpi .get ()/ 72.0 ))
853880
854881 def tick_top (self ):
855882 'use ticks only on top'
@@ -904,6 +931,20 @@ def _get_label(self):
904931 self ._set_artist_props (label )
905932 self .label_position = 'left'
906933 return label
934+
935+ def _get_offset_text (self ):
936+ # x in display coords, y in axes coords (to be updated at draw time)
937+ offsetText = Text (x = 0 , y = 0.5 ,
938+ fontproperties = FontProperties (size = rcParams ['tick.labelsize' ]),
939+ color = rcParams ['tick.color' ],
940+ verticalalignment = 'bottom' ,
941+ horizontalalignment = 'left' ,
942+ )
943+ offsetText .set_transform (blend_xy_sep_transform (self .axes .transAxes ,
944+ identity_transform ()) )
945+ self ._set_artist_props (offsetText )
946+ self .offset_text_position = 'left'
947+ return offsetText
907948
908949 def get_label_position (self ):
909950 """
@@ -924,7 +965,7 @@ def set_label_position(self, position):
924965 self .label .set_horizontalalignment ('right' )
925966 self .label_position = position
926967
927- def _update_label_postion (self , bboxes , bboxes2 ):
968+ def _update_label_position (self , bboxes , bboxes2 ):
928969 """
929970 Update the label position based on the sequence of bounding
930971 boxes of all the ticklabels
@@ -950,6 +991,15 @@ def _update_label_postion(self, bboxes, bboxes2):
950991 right = bbox .xmax ()
951992
952993 self .label .set_position ( (right + self .LABELPAD * self .figure .dpi .get ()/ 72.0 , y ))
994+
995+ def _update_offset_text_position (self , bboxes , bboxes2 ):
996+ """
997+ Update the offset_text position based on the sequence of bounding
998+ boxes of all the ticklabels
999+ """
1000+ x ,y = self .offsetText .get_position ()
1001+ top = self .axes .bbox .ymax ()
1002+ self .offsetText .set_position ((x , top + self .OFFSETTEXTPAD * self .figure .dpi .get ()/ 72.0 ))
9531003
9541004 def tick_right (self ):
9551005 'use ticks only on right'
0 commit comments