Example of how to replace the default log-plot exponential labels with integer labels. The same method will work for any kind of custom labeling. This example was pulled from the Python-list mailing list and the original can be found here.

```   1 from pylab import *
2
3 def log_10_product(x, pos):
4     """The two args are the value and tick position.
5     Label ticks with the product of the exponentiation"""
6     return '%1i' % (x)
7
8 # Axis scale must be set prior to declaring the Formatter
9 # If it is not the Formatter will use the default log labels for ticks.
10 ax = subplot(111)
11 ax.set_xscale('log')
12 ax.set_yscale('log')
13
14 formatter = FuncFormatter(log_10_product)
15 ax.xaxis.set_major_formatter(formatter)
16 ax.yaxis.set_major_formatter(formatter)
17
18 # Create some artificial data.
19 result1 = [3, 5, 70, 700, 900]
20 result2 = [1000, 2000, 3000, 4000, 5000]
21 predict1 = [4, 8, 120, 160, 200]
22 predict2 = [2000, 4000, 6000, 8000, 1000]
23
24 # Plot
25 ax.scatter(result1, predict1, s=40, c='b', marker='s', faceted=False)
26 ax.scatter(result2, predict2, s=40, c='r', marker='s', faceted=False)
27
28 ax.set_xlim(1e-1, 1e4)
29 ax.set_ylim(1e-1, 1e4)
30 grid(True)
31
32 xlabel(r"Result", fontsize = 12)
33 ylabel(r"Prediction", fontsize = 12)
```

Cookbook/Matplotlib/CustomLogLabels (last edited 2008-09-17 01:38:37 by jesrl)