How can I avoid sharey tick ovelap?

Hi all,

  I use sharey functionality on a regular basis for my plots.

Nice,but ticks are sometime overlapping and are unreadable in the top-left corner (see figure joined).
Also joined, a small script reproducing the problem.

How could I avoid this overlapping?

Thanks

David

two_scale_y.py (377 Bytes)

image.png

How could I avoid this overlapping?

What about deleting your first tick on ax2, with

ax2.set_xticks(ax2.get_xticks()[1:])

at the end of your code ?

Or, you can change the formatter of your yaxis to OldScalarFormatter, which
renders the scientific notation in each tick label, rather than at the top of
the axis.

···

On Friday 24 November 2006 3:10 pm, Pierre GM wrote:

> How could I avoid this overlapping?

What about deleting your first tick on ax2, with

>>> ax2.set_xticks(ax2.get_xticks()[1:])

at the end of your code ?

Thinking about it: is there a way to grab this scientific notation ? The idea
would be to get the corresponding object as a string, and update the ylabel
with it.

···

On Friday 24 November 2006 15:14, Darren Dale wrote:

Or, you can change the formatter of your yaxis to OldScalarFormatter, which
renders the scientific notation in each tick label, rather than at the top
of the axis.

Yes, the scientific notation is a matplotlib text object, which you can grab
like this:

plot([0,1e10])
a=gca()
t=a.yaxis.get_offset_text()

and then you can get the string:

s=t.get_text()

Darren

···

On Friday 24 November 2006 3:34 pm, Pierre GM wrote:

On Friday 24 November 2006 15:14, Darren Dale wrote:
> Or, you can change the formatter of your yaxis to OldScalarFormatter,
> which renders the scientific notation in each tick label, rather than at
> the top of the axis.

Thinking about it: is there a way to grab this scientific notation ? The
idea would be to get the corresponding object as a string, and update the
ylabel with it.

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 (???) (see bottom right of the new example).

I join a new example reproducing both problems.

2006/11/24, Pierre GM <

pgmdevlist@…287…>:

image.png

two_scale2_y.py (382 Bytes)

···

How could I avoid this overlapping?

What about deleting your first tick on ax2, with

ax2.set_xticks(ax2.get_xticks()[1:])
at the end of your code ?

Note: same problem applied for sharex…

2006/11/24, David TREMOUILLES <david.trem@…287…>:

···

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 (???) (see bottom right of the new example).

I join a new example reproducing both problems.

2006/11/24, Pierre GM <

pgmdevlist@…287…>:

How could I avoid this overlapping?

What about deleting your first tick on ax2, with

ax2.set_xticks(ax2.get_xticks()[1:])
at the end of your code ?

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):