The patch at the end of this post *should* render the scaling factor above the
xaxis labels on the top axis. It should, but it doesn't. Instead, it renders
the scaling factor overlapping the tick labels on the top axis. I don't
understand this behavior, considering the scaling factor is properly rendered
if the bottom axis is the one that is labeled.
As for overlapping with twinx and twiny, I don't know how best to proceed
here. The offset_text's parent axis would have to inspect its own ticklabels
as well as the ticklabels of the OTHER axis, and based on their extent, find
a new location for the offset_text. This is starting to get in the realm of
requiring a layout manager in order to implement properly.
I'm preparing for a professional meeting next week (anyone else going to MRS
in Boston?) and don't have time to continue working on this. Perhaps the
patch is enough to get someone else pointed in the right direction.
Darren
Index: lib/matplotlib/axis.py
···
On Friday 24 November 2006 3:46 pm, David TREMOUILLES wrote:
Well... deleting the first is not a solution for me
My app use pan/zoom tool for manual adjustment of the plot.
if I put the line you proposed at the end of my code, the x upper labels
are not
dynamically updated anymore and could be that one end bellow the "scaling
factor" "x1e4" of the y labels...
Change the formatter of the yaxis to OldScalarFormatter do the trick but I
would prefer to use the default formatter.
Would it be possible to move the "x1e4" to the left to avoid the
overlapping?
By the way I've just discover kind of bug: the scaling factor of the x top
axis is displayed on the x bottom axis
===================================================================
--- lib/matplotlib/axis.py (revision 2898)
+++ lib/matplotlib/axis.py (working copy)
@@ -868,7 +868,7 @@
offsetText.set_transform( blend_xy_sep_transform(
self.axes.transAxes,
identity_transform() ))
self._set_artist_props(offsetText)
- self.offset_text_position='bottom'
+## self.offset_text_position='bottom'
return offsetText
def get_label_position(self):
@@ -923,13 +923,28 @@
boxes of all the ticklabels
"""
x,y = self.offsetText.get_position()
- if not len(bboxes):
- bottom = self.axes.bbox.ymin()
+ position = self.get_ticks_position()
+ if position == 'top':
+ if not len(bboxes):
+ top = self.axes.bbox.ymax()
+ else:
+ bbox = bbox_all(bboxes)
+ top = bbox.ymax()
+ self.offsetText.set_position((x,
top+self.OFFSETTEXTPAD*self.figure.dpi.get()/72.0))
else:
- bbox = bbox_all(bboxes)
- bottom = bbox.ymin()
- self.offsetText.set_position((x,
bottom-self.OFFSETTEXTPAD*self.figure.dpi.get()/72.0))
+ if not len(bboxes):
+ bottom = self.axes.bbox.ymin()
+ else:
+ bbox = bbox_all(bboxes)
+ bottom = bbox.ymin()
+ self.offsetText.set_position((x,
bottom-self.OFFSETTEXTPAD*self.figure.dpi.get()/72.0))
+ def set_offset_position(self, position):
+ assert position == 'top' or position == 'bottom'
+
+ if position == 'top': self.offsetText.set_va('bottom')
+ else: self.offsetText.set_va('top')
+
def set_ticks_position(self, position):
"""
Set the ticks position (top, bottom, both or default)
@@ -946,24 +961,28 @@
ticks.extend( self.minorTicks )
if position == 'top':
+ self.set_offset_position('top')
for t in ticks:
t.tick1On = False
t.tick2On = True
t.label1On = False
t.label2On = True
elif position == 'bottom':
+ self.set_offset_position('bottom')
for t in ticks:
t.tick1On = True
t.tick2On = False
t.label1On = True
t.label2On = False
elif position == 'default':
+ self.set_offset_position('bottom')
for t in ticks:
t.tick1On = True
t.tick2On = True
t.label1On = True
t.label2On = False
else:
+ self.set_offset_position('bottom')
for t in ticks:
t.tick1On = True
t.tick2On = True
@@ -1042,7 +1061,7 @@
offsetText.set_transform(blend_xy_sep_transform(self.axes.transAxes,
identity_transform()) )
self._set_artist_props(offsetText)
- self.offset_text_position='left'
+## self.offset_text_position='left'
return offsetText
def get_label_position(self):