0

I have a semilog plot to base e and it looks like that. How can I get rid of the numeric rendering of 2.71... and instead display it as e?

enter image description here

plt.figure()
(_, caps, _) = plt.errorbar(xarr, yarr, xerr=xarr_stddev, yerr=yarr_stddev, fmt='.', markersize=1, linewidth=0.25, capsize=1)
for cap in caps:
    cap.set_markeredgewidth(0.25)
plt.grid()
plt.xlabel(r"$t$ [s]")
plt.ylabel(r"$dV/dt$ [V/s]")
plt.yscale('log', basey=np.e)
plt.title('Decay')
plt.savefig("plot_1.pdf", papertype = 'a4', format = 'pdf')

(BTW the three lines of code in the beginning are for the error bar caps which were missing for me. Went after this solution)

mdcq
  • 1,593
  • 13
  • 30

1 Answers1

3

The simplest way is to write your own FuncFormatter and use it for Y axis. Adding the following lines

from matplotlib.ticker import FuncFormatter

def format_labels(x, pos):
    return "e$^{%i}$" % np.log(x)

to the graph and setting the formatter just above the savefig line:

plt.gca().yaxis.set_major_formatter(FuncFormatter(format_labels))

lead to the following graph:

enter image description here

Andrey Sobolev
  • 12,353
  • 3
  • 48
  • 52