Closed
Description
Problem
Taken from here, I found the following ticks (from plt.semilogy([1.5, 50])
):
Not informative enough. I wish there was an easy way to set_minor_formatter
such that say e.g 2x10^0
, 3x10^0
would have been displayed. I tried to use (full MWE this time):
import matplotlib.pyplot as plt
from matplotlib import ticker
plt.semilogy([1.5, 50])
plt.gca().yaxis.set_minor_formatter(ticker.LogFormatter(base=10, labelOnlyBase=True))
plt.show()
But it changed nothing. OTH I was capable to obtain my desired output with:
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker
plt.semilogy([1.5, 50])
def get_minor_tick_string(x, pos):
b = np.floor(np.log10(x)).astype(int)
p = pos % 8
if p < 3:
return f"${p+2}\\cdot 10^{b}$"
else:
return ""
plt.gca().yaxis.set_minor_formatter(get_minor_tick_string)
plt.show()
But I'm sure it is not very versatile. It produces:
Which is not bad.
Proposed solution
I'd like to first explain in the docs / fix the behavior of set_minor_formatter(ticker.LogFormatter(base=10, labelOnlyBase=True))
. 2ndly, I'd like to discuss the possibility of adding tick labels as shown above, because I think I'm not the only one that was not satisfied by this default behavior.