Skip to content

Commit 600ba80

Browse files
committed
fixed log coord formatting
svn path=/trunk/matplotlib/; revision=721
1 parent 206b16c commit 600ba80

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

lib/matplotlib/axes.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from artist import Artist
1010
from axis import XAxis, YAxis
1111
from cbook import iterable, is_string_like, flatten, enumerate, True, False,\
12-
allequal, dict_delall
12+
allequal, dict_delall, strip_math
1313
from collections import RegularPolyCollection, PolyCollection
1414
from colors import colorConverter, normalize, Colormap, LinearSegmentedColormap
1515
import cm
@@ -496,7 +496,15 @@ def format_xdata(self, x):
496496
try: return self.fmt_xdata(x)
497497
except TypeError:
498498
func = self.xaxis.get_major_formatter()
499-
return func(x)
499+
# log formatters label only the decades which is not what
500+
# we want for coord formatting. hackish, yes
501+
if isinstance(func, LogFormatter) and func.labelOnlyBase:
502+
func.labelOnlyBase = False
503+
val = strip_math(func(x))
504+
func.labelOnlyBase = True
505+
else:
506+
val = func(x)
507+
return val
500508

501509
def format_ydata(self, y):
502510
"""\
@@ -507,7 +515,15 @@ def format_ydata(self, y):
507515
try: return self.fmt_ydata(y)
508516
except TypeError:
509517
func = self.yaxis.get_major_formatter()
510-
return func(y)
518+
# log formatters label only the decades which is not what
519+
# we want for coord formatting. hackish, yes
520+
if isinstance(func, LogFormatter) and func.labelOnlyBase:
521+
func.labelOnlyBase = False
522+
val = strip_math(func(y))
523+
func.labelOnlyBase = True
524+
else:
525+
val = func(y)
526+
return val
511527

512528
def format_coord(self, x, y):
513529
'return a format string formatting the x, y coord'

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88

99
from matplotlib import verbose
10-
from cbook import is_string_like, enumerate, True, False
10+
from cbook import is_string_like, enumerate, True, False, strip_math
1111
from colors import colorConverter
1212
from numerix import array, sqrt, pi, log, asarray, ones, Float
1313
from patches import Rectangle
@@ -308,11 +308,8 @@ def draw_rectangle(self, gcEdge, gcFace, x, y, width, height):
308308
pass # derived must override
309309

310310
def strip_math(self, s):
311-
remove = (r'\rm', '\cal', '\tt', '\it', '\\', '{', '}')
312-
s = s[1:-1]
313-
for r in remove: s = s.replace(r,'')
314-
return s
315-
311+
return strip_math(s)
312+
316313
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
317314
"""
318315
Draw string s at x,y (display coords) with font properties

lib/matplotlib/cbook.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
False = False
1616

1717

18+
def strip_math(s):
19+
'remove latex formatting from mathtext'
20+
remove = (r'\rm', '\cal', '\tt', '\it', '\\', '{', '}')
21+
s = s[1:-1]
22+
for r in remove: s = s.replace(r,'')
23+
return s
24+
1825
class Bunch:
1926
"""
2027
Often we want to just collect a bunch of stuff together, naming each

lib/matplotlib/ticker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ def pprint_val(self, x, d):
234234
class LogFormatter(ScalarFormatter):
235235
"""
236236
Format values for log axis;
237+
238+
if attribute decadeOnly is True, only the decades will be labelled.
237239
"""
238240
def __init__(self, base=10.0, labelOnlyBase = True):
239241
"""
@@ -243,14 +245,16 @@ def __init__(self, base=10.0, labelOnlyBase = True):
243245
"""
244246
self.base = base+0.0
245247
self.labelOnlyBase=labelOnlyBase
246-
248+
self.decadeOnly = True
249+
247250
def base(self,base):
248251
'change the base for labeling - warning: should always match the base used for LogLocator'
249252
self.base=base
250253

251254
def label_minor(self,labelOnlyBase):
252255
'switch on/off minor ticks labeling'
253256
self.labelOnlyBase=labelOnlyBase
257+
254258

255259
def __call__(self, x, pos=0):
256260
'Return the format for tick val x at position pos'

0 commit comments

Comments
 (0)