Why can I not format the labels on a semilogx plot?

Hi everyone,

I have been using code similar to the below to format the labels on scatter plots with the x axis
set to a logarithmic scale. However when I try the below I still get the base and exponent instead
of the product (ie '10**2' instead of '100'). Can anyone tell me what I am doing wrong? Sorry
about the large data sample but I figured it was best to be as accurate as possible.

Thanks,
Derek

from pylab import *
import math

def log10Product(x, pos):
    """The two args are the value and tick position.
    Label ticks with the product of the exponentiation"""
    return '%1i' % (x)

def roundUpLogDecade(x):
    """ Round up to the nearest logarithmic decade"""
    return 10**math.ceil(math.log10(x))

x_axis = [0.93820000000000003, 0.93820000000000003, 1.4981, 3.0781000000000001,
5.1627999999999998, 5.4006999999999996, 6.4268000000000001, 7.2370000000000001,
9.0183999999999997, 9.3475999999999999, 10.856999999999999, 11.066000000000001,
11.382999999999999, 11.473000000000001, 12.324, 14.512, 16.82, 19.260999999999999,
21.702999999999999, 22.384, 23.899999999999999, 27.716000000000001, 33.753, 38.012,
42.079999999999998, 42.241, 42.656999999999996, 45.177, 46.899999999999999, 49.518999999999998,
51.344999999999999, 52.948999999999998, 64.768000000000001, 65.808999999999997,
66.600999999999999, 66.897999999999996, 67.953999999999994, 67.960999999999999,
73.228999999999999, 73.650000000000006, 78.744, 79.030000000000001, 82.275000000000006,
83.905000000000001, 98.102999999999994, 100.16, 104.84999999999999, 112.56, 126.83,
128.03999999999999, 134.13, 135.43000000000001, 139.5, 148.02000000000001, 153.88, 167.88,
173.90000000000001, 189.97999999999999, 192.00999999999999, 194.66999999999999,
210.25999999999999, 228.90000000000001, 240.83000000000001, 241.34999999999999, 267.69,
268.54000000000002, 268.68000000000001, 276.86000000000001, 292.23000000000002,
294.00999999999999, 295.61000000000001, 305.18000000000001, 313.11000000000001, 315.69,
339.06999999999999, 347.31, 351.27999999999997, 377.97000000000003, 380.61000000000001,
386.07999999999998, 395.48000000000002, 405.25, 423.26999999999998, 427.58999999999997,
434.27999999999997, 455.74000000000001, 473.39999999999998, 474.16000000000003,
479.23000000000002, 518.32000000000005, 533.91999999999996, 539.64999999999998,
540.85000000000002, 580.74000000000001, 585.59000000000003, 600.94000000000005,
611.63999999999999, 638.86000000000001, 665.45000000000005, 697.75999999999999,
754.64999999999998, 815.99000000000001, 818.88, 881.97000000000003, 883.62, 886.70000000000005,
912.51999999999998, 932.30999999999995, 969.55999999999995, 980.72000000000003, 1057.2,
1171.4000000000001, 1188.0999999999999, 1220.9000000000001, 1245.2, 1301.2, 1349.0999999999999,
1355.5, 1357.4000000000001, 1361.5999999999999, 1378.5, 1435.2, 1482.9000000000001,
1496.9000000000001, 1510.3, 1549.5, 1569.0999999999999, 1574.4000000000001, 1602.5, 1608.8,
1651.2, 1705.8, 1798.0999999999999, 1867.2, 1870.7, 2044.4000000000001, 2048.8000000000002,
2092.0999999999999, 2183.9000000000001, 2382.4000000000001, 2506.5999999999999,
2555.0999999999999, 2665.5999999999999, 2753.3000000000002, 2815.1999999999998,
2950.6999999999998, 2996.3000000000002, 3068.0999999999999, 3287.6999999999998,
3313.8000000000002, 3382.5999999999999, 3427.6999999999998, 3467.3000000000002,
3505.9000000000001, 3640.0, 3805.8000000000002, 3889.6999999999998, 3984.8000000000002, 4094.5,
4123.1000000000004, 4224.8000000000002, 4242.8000000000002, 4245.1999999999998,
4499.1999999999998, 4552.6999999999998, 4675.8999999999996, 4744.1999999999998,
4816.3000000000002, 5051.3999999999996, 5138.0, 5690.5, 5800.6000000000004, 6065.0,
6337.1000000000004, 6829.3000000000002, 7285.5, 7310.8000000000002, 7489.1000000000004, 7534.5,
8319.2000000000007, 8976.7999999999993, 9283.2999999999993, 9699.2000000000007, 9767.5, 10895.0,
11247.0, 11454.0, 11631.0, 11661.0, 12096.0, 12536.0, 13030.0, 13117.0, 13179.0, 13376.0, 13515.0,
13519.0, 14708.0, 14954.0, 15329.0, 15336.0, 16031.0, 16625.0, 16883.0, 17730.0, 18511.0, 19191.0,
19219.0, 20144.0, 23457.0, 24807.0, 26801.0, 28435.0, 29286.0, 29382.0, 31013.0, 31665.0, 34811.0,
34961.0, 35997.0, 36588.0, 42922.0, 46101.0, 48096.0, 49627.0, 59298.0, 59775.0, 60756.0, 73322.0,
78387.0, 79868.0, 89046.0, 89655.0, 112410.0, 118700.0, 125460.0, 126660.0, 136190.0, 138140.0,
143090.0, 145420.0, 151440.0, 155060.0, 159980.0, 161240.0, 168830.0, 171290.0, 175630.0,
184960.0, 192330.0, 202910.0, 211700.0, 235890.0, 241170.0, 260540.0, 273750.0, 342660.0,
379170.0, 379560.0, 414240.0, 418600.0, 436640.0, 436760.0, 554500.0, 650750.0, 759950.0,
799680.0, 922060.0, 1000000.0]
fp_y_axis = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0044247787610619468, 0.0088495575221238937,
0.0088495575221238937, 0.013274336283185841, 0.013274336283185841, 0.017699115044247787,
0.022123893805309734, 0.022123893805309734, 0.022123893805309734, 0.026548672566371681,
0.026548672566371681, 0.030973451327433628, 0.035398230088495575, 0.035398230088495575,
0.035398230088495575, 0.035398230088495575, 0.039823008849557522, 0.044247787610619468,
0.044247787610619468, 0.048672566371681415, 0.048672566371681415, 0.053097345132743362,
0.057522123893805309, 0.061946902654867256, 0.061946902654867256, 0.06637168141592921,
0.070796460176991149, 0.070796460176991149, 0.070796460176991149, 0.075221238938053103,
0.075221238938053103, 0.075221238938053103, 0.075221238938053103, 0.075221238938053103,
0.079646017699115043, 0.079646017699115043, 0.079646017699115043, 0.084070796460176997,
0.088495575221238937, 0.092920353982300891, 0.092920353982300891, 0.097345132743362831,
0.10176991150442478, 0.10619469026548672, 0.11061946902654868, 0.11504424778761062,
0.11504424778761062, 0.11946902654867257, 0.12389380530973451, 0.12389380530973451,
0.12389380530973451, 0.12831858407079647, 0.13274336283185842, 0.13716814159292035,
0.1415929203539823, 0.1415929203539823, 0.14601769911504425, 0.15044247787610621,
0.15044247787610621, 0.15044247787610621, 0.15044247787610621, 0.15486725663716813,
0.15929203539823009, 0.16371681415929204, 0.16814159292035399, 0.17256637168141592,
0.17699115044247787, 0.17699115044247787, 0.18141592920353983, 0.18141592920353983,
0.18584070796460178, 0.19026548672566371, 0.19469026548672566, 0.19911504424778761,
0.20353982300884957, 0.20353982300884957, 0.20796460176991149, 0.20796460176991149,
0.20796460176991149, 0.21238938053097345, 0.21238938053097345, 0.21238938053097345,
0.2168141592920354, 0.22123893805309736, 0.22123893805309736, 0.22566371681415928,
0.23008849557522124, 0.23008849557522124, 0.23451327433628319, 0.23451327433628319,
0.23893805309734514, 0.24336283185840707, 0.24336283185840707, 0.24778761061946902,
0.25221238938053098, 0.25663716814159293, 0.26106194690265488, 0.26106194690265488,
0.26548672566371684, 0.26991150442477874, 0.26991150442477874, 0.27433628318584069,
0.27876106194690264, 0.2831858407079646, 0.28761061946902655, 0.29203539823008851,
0.29646017699115046, 0.30088495575221241, 0.30530973451327431, 0.30973451327433627,
0.31415929203539822, 0.31858407079646017, 0.32300884955752213, 0.32300884955752213,
0.32300884955752213, 0.32743362831858408, 0.33185840707964603, 0.33628318584070799,
0.33628318584070799, 0.34070796460176989, 0.34513274336283184, 0.34513274336283184,
0.34955752212389379, 0.35398230088495575, 0.3584070796460177, 0.36283185840707965,
0.36725663716814161, 0.37168141592920356, 0.37168141592920356, 0.37610619469026546,
0.38053097345132741, 0.38495575221238937, 0.38938053097345132, 0.39380530973451328,
0.39823008849557523, 0.40265486725663718, 0.40707964601769914, 0.41150442477876104,
0.41592920353982299, 0.41592920353982299, 0.42035398230088494, 0.4247787610619469,
0.42920353982300885, 0.4336283185840708, 0.43805309734513276, 0.44247787610619471,
0.44690265486725661, 0.45132743362831856, 0.45132743362831856, 0.45575221238938052,
0.46017699115044247, 0.46460176991150443, 0.46902654867256638, 0.47345132743362833,
0.47787610619469029, 0.48230088495575218, 0.48672566371681414, 0.49115044247787609,
0.49115044247787609, 0.49557522123893805, 0.5, 0.5, 0.50442477876106195, 0.50884955752212391,
0.50884955752212391, 0.51327433628318586, 0.51769911504424782, 0.52212389380530977,
0.52654867256637172, 0.53097345132743368, 0.53539823008849563, 0.53982300884955747,
0.54424778761061943, 0.54867256637168138, 0.55309734513274333, 0.55752212389380529,
0.56194690265486724, 0.5663716814159292, 0.57079646017699115, 0.5752212389380531,
0.5752212389380531, 0.57964601769911506, 0.58407079646017701, 0.58849557522123896,
0.59292035398230092, 0.59734513274336287, 0.60176991150442483, 0.60619469026548678,
0.61061946902654862, 0.61504424778761058, 0.61946902654867253, 0.62389380530973448,
0.62831858407079644, 0.63274336283185839, 0.63716814159292035, 0.6415929203539823,
0.64601769911504425, 0.65044247787610621, 0.65486725663716816, 0.65929203539823011,
0.66371681415929207, 0.66814159292035402, 0.67256637168141598, 0.67699115044247793,
0.68141592920353977, 0.68584070796460173, 0.69026548672566368, 0.69469026548672563,
0.69911504424778759, 0.70353982300884954, 0.70796460176991149, 0.71238938053097345,
0.7168141592920354, 0.72123893805309736, 0.72566371681415931, 0.73008849557522126,
0.73451327433628322, 0.73893805309734517, 0.74336283185840712, 0.74778761061946908,
0.75221238938053092, 0.75663716814159288, 0.76106194690265483, 0.76548672566371678,
0.76991150442477874, 0.77433628318584069, 0.77876106194690264, 0.7831858407079646,
0.78761061946902655, 0.79203539823008851, 0.79646017699115046, 0.80088495575221241,
0.80530973451327437, 0.80973451327433632, 0.81415929203539827, 0.81858407079646023,
0.82300884955752207, 0.82743362831858402, 0.83185840707964598, 0.83628318584070793,
0.84070796460176989, 0.84513274336283184, 1.0]
tp_y_axis = [0.0, 0.012987012987012988, 0.025974025974025976, 0.03896103896103896,
0.051948051948051951, 0.064935064935064929, 0.07792207792207792, 0.090909090909090912,
0.1038961038961039, 0.11688311688311688, 0.12987012987012986, 0.14285714285714285,
0.15584415584415584, 0.16883116883116883, 0.18181818181818182, 0.19480519480519481,
0.20779220779220781, 0.22077922077922077, 0.23376623376623376, 0.24675324675324675,
0.25974025974025972, 0.27272727272727271, 0.2857142857142857, 0.29870129870129869,
0.31168831168831168, 0.32467532467532467, 0.32467532467532467, 0.32467532467532467,
0.33766233766233766, 0.33766233766233766, 0.35064935064935066, 0.35064935064935066,
0.35064935064935066, 0.36363636363636365, 0.37662337662337664, 0.37662337662337664,
0.38961038961038963, 0.38961038961038963, 0.38961038961038963, 0.40259740259740262,
0.41558441558441561, 0.42857142857142855, 0.42857142857142855, 0.42857142857142855,
0.44155844155844154, 0.44155844155844154, 0.45454545454545453, 0.45454545454545453,
0.45454545454545453, 0.45454545454545453, 0.46753246753246752, 0.46753246753246752,
0.46753246753246752, 0.48051948051948051, 0.4935064935064935, 0.4935064935064935,
0.50649350649350644, 0.51948051948051943, 0.53246753246753242, 0.54545454545454541,
0.54545454545454541, 0.55844155844155841, 0.5714285714285714, 0.5714285714285714,
0.5714285714285714, 0.5714285714285714, 0.58441558441558439, 0.58441558441558439,
0.58441558441558439, 0.58441558441558439, 0.58441558441558439, 0.58441558441558439,
0.59740259740259738, 0.59740259740259738, 0.59740259740259738, 0.61038961038961037,
0.62337662337662336, 0.62337662337662336, 0.62337662337662336, 0.62337662337662336,
0.62337662337662336, 0.63636363636363635, 0.63636363636363635, 0.63636363636363635,
0.64935064935064934, 0.66233766233766234, 0.67532467532467533, 0.67532467532467533,
0.67532467532467533, 0.67532467532467533, 0.67532467532467533, 0.67532467532467533,
0.67532467532467533, 0.68831168831168832, 0.68831168831168832, 0.70129870129870131,
0.70129870129870131, 0.70129870129870131, 0.70129870129870131, 0.70129870129870131,
0.70129870129870131, 0.7142857142857143, 0.7142857142857143, 0.72727272727272729,
0.74025974025974028, 0.74025974025974028, 0.75324675324675328, 0.76623376623376627,
0.76623376623376627, 0.76623376623376627, 0.77922077922077926, 0.77922077922077926,
0.77922077922077926, 0.79220779220779225, 0.79220779220779225, 0.80519480519480524,
0.80519480519480524, 0.80519480519480524, 0.81818181818181823, 0.81818181818181823,
0.81818181818181823, 0.81818181818181823, 0.81818181818181823, 0.83116883116883122,
0.83116883116883122, 0.83116883116883122, 0.8441558441558441, 0.8441558441558441,
0.8441558441558441, 0.8441558441558441, 0.8441558441558441, 0.8441558441558441,
0.8441558441558441, 0.8441558441558441, 0.8441558441558441, 0.8441558441558441,
0.8441558441558441, 0.8441558441558441, 0.8441558441558441, 0.8571428571428571,
0.87012987012987009, 0.87012987012987009, 0.87012987012987009, 0.87012987012987009,
0.88311688311688308, 0.88311688311688308, 0.88311688311688308, 0.89610389610389607,
0.89610389610389607, 0.89610389610389607, 0.89610389610389607, 0.89610389610389607,
0.89610389610389607, 0.89610389610389607, 0.90909090909090906, 0.90909090909090906,
0.90909090909090906, 0.90909090909090906, 0.90909090909090906, 0.90909090909090906,
0.90909090909090906, 0.90909090909090906, 0.90909090909090906, 0.90909090909090906,
0.90909090909090906, 0.92207792207792205, 0.92207792207792205, 0.92207792207792205,
0.92207792207792205, 0.92207792207792205, 0.92207792207792205, 0.92207792207792205,
0.92207792207792205, 0.92207792207792205, 0.93506493506493504, 0.93506493506493504,
0.93506493506493504, 0.93506493506493504, 0.93506493506493504, 0.93506493506493504,
0.93506493506493504, 0.93506493506493504, 0.93506493506493504, 0.93506493506493504,
0.94805194805194803, 0.94805194805194803, 0.94805194805194803, 0.96103896103896103,
0.96103896103896103, 0.96103896103896103, 0.97402597402597402, 0.97402597402597402,
0.97402597402597402, 0.97402597402597402, 0.97402597402597402, 0.97402597402597402,
0.97402597402597402, 0.97402597402597402, 0.97402597402597402, 0.97402597402597402,
0.97402597402597402, 0.97402597402597402, 0.97402597402597402, 0.97402597402597402,
0.97402597402597402, 0.97402597402597402, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701,
0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 0.98701298701298701, 1.0]

ax = subplot(111)
ax.set_xscale('log')
            
formatter = FuncFormatter(log10Product)
ax.xaxis.set_major_formatter(formatter)

ax.semilogx(x_axis, fp_y_axis, 'r', linewidth=0.1, markersize=2, label = "False Positive")
ax.semilogx(x_axis, tp_y_axis, 'b', linewidth=0.1, markersize=2, label = "True Positive")

max_xlim = roundUpLogDecade(max(x_axis))
## Must add 1 to allow the last decades label to be shown
ax.set_xlim(1e-1, max_xlim+1)
        
legend(loc=1)
xlabel(r"Prediction", fontsize = 12)
ylabel(r"Rate", fontsize = 12)
grid(True)
show()

···

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com