Alexander Michael wrote:
On 8/3/06, *Steve Schmerler* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
wrote:
Hi all
How can I change the default behavior of the tick labeling from say
1 2 3 4 x1e-5
to
1e-5 2e-5 3e-5 4e-5 ?
My thesis supervisor wants it that way :(
cheers,
steve
There is problably a better way, but onne way is to set the label
formatter yourself:
import pylab
import matplotlib
pylab.plot([1.0E-5,2.5E-5,3.0E-5], [1.0, 3.0, 2.0])
ax = pylab.gca()
ax.xaxis.set_major_formatter(
matplotlib.ticker.FormatStrForm
atter('%g'))
pylab.show()
You can craft an arbitrarily constructed string by using
matplotlib.ticker.FuncFormatter
instead of matplotlib.ticker.FormatStrFormatter.
Hope this helps,
Alex
Yes, after a look at the docs I found that FuncFormatter is what I
wanted. With the help of a little function (which I wrote some time ago)
that converts a float number into a raw string I can use FuncFormatter
straightforward (see attached file).
cheers,
steve
--
Random number generation is the art of producing pure gibberish as
quickly as possible.
from pylab import *
from numpy import logspace
##import utils
##from mpl_settings import *
rcParams['text.usetex'] = True
def make_label(num, precision = 3, format = 'e', start_text = ''):
"""
Convert number 'num' into raw string for matplotlib labels.
"""
format_str = '%.' + str(precision) + format
s = format_str %num
if format == 'e':
ss = s.split(format)
float_str = ss[0]
ex = ss[1]
# '+05' -> '05'
if ex.startswith('+'):
ex = ex[1:]
while ex.startswith('0'):
ex = ex[1:]
elif ex.startswith('-'):
while ex.startswith('-0'):
ex = ex[0] + ex[2:]
if ex != '':
label_str = r'$%s%s\times 10^{%s}$' %(start_text, float_str, ex)
else:
label_str = r'$%s%s$' %(start_text, float_str)
elif format == 'f':
label_str = r'$%s%s$' %(start_text, s)
else:
raise StandardError, "[make_label] only formats 'e' and 'f' allowed"
sys.exit(1)
return label_str
def ax_tick_format(num, pos):
## return utils.make_label(num, precision = 2)
return make_label(num, precision = 2)
formatter = FuncFormatter(ax_tick_format)
f = figure()
ax = f.gca()
ax.yaxis.set_major_formatter(formatter)
y = logspace(-1,-30,100)
plot(y)
ylabel('lalala')
subplots_adjust(left=0.15)
show()
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users