In the following code, is it possible to pull 5 out as an offset on the x-axis? I am using FuncFormatter to change the format to 5 * 10^x. But the repetitive 5 needs to be pulled aside. FuncFormatter does not seem to support offsetting.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as mticker
import math
from matplotlib.ticker import ScalarFormatter
fig, ax = plt.subplots(figsize=(8, 4))
ticks = [5e-1, 5e-2, 5e-3, 5e-4, 5e-5, 5e-6]
x = [
0.4948443711340206,
0.48525674226804116,
0.12300168762886599,
0.01886658762886597,
0.0012371876288659789,
0.0002577783505154638,
0.0002577783505154638,
0.0002577783505154638,
0.0002577783505154638,
0.0002577783505154638,
0.0
]
y = [
0.0,
0.00199151728,
0.00398303456,
0.00597455184,
0.00796606912,
0.009957586400000001,
0.010455465720000001,
0.010953345040000001,
0.011451224360000001,
0.011949103680000002,
0.012446983000000002
]
ax.set_xticks(ticks)
ax.set_xticklabels(ticks)
fmt = mticker.FuncFormatter(lambda v, _: ("$5x10^{%d}$" % (math.log(v, 10) - 1)))
ax.xaxis.set_major_formatter(fmt)
ax.xaxis.major.formatter._useMathText = True
ax.plot(x, y)
plt.show()
Code with minimal example http://tpcg.io/_WHS6G4
