Matplotlib
inherently sets logarithmic scales to use scientific notation. If you want to avoid this you have to use a workaround such as the following minimal example:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
x=np.arange(100,110)
y=np.arange(10)
fig, axes = plt.subplots(1, 2, sharey=True, squeeze=False)
axes = axes[0]
axes[0].plot(x,y)
axes[1].plot(x,y)
for ax in axes:
ax.set_yscale('log')
ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
plt.show()
This works fine under all cases and has been shown as a solution as under many questions such as Example 1 Example 2
I have used this solution fine before. However there is another issue that I have not seen discussed. If you want to set a ax.ylim(...)
this work around stops working
Consider the following example (note the new line ax.set_ylim(0,10)
):
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
x=np.arange(100,110)
y=np.arange(10)
fig, axes = plt.subplots(1, 2, sharey=True, squeeze=False)
axes = axes[0]
axes[0].plot(x,y)
axes[1].plot(x,y)
for ax in axes:
ax.set_ylim(0, 10)
ax.set_yscale('log')
ax.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
plt.show()
This is no longer the desired output.
Is there anyway to avoid this weird interaction?