Bug report
Bug summary
MaxNLocator changes the scientific notation with different number of tick labels.
Code for reproduction
I encountered this unexpected behavior when I changed the y-ticklabel size. Going from size 13 to 14 changes the scientific notation from 1e9 to 1e10, and adds an decimal offset to all the ticklabels.
import matplotlib.pyplot as plt
sci_nums = [10**9, 8*10**9]
plt.rcParams['ytick.labelsize'] = 13
fig, ax = plt.subplots()
ax.scatter(range(len(sci_nums)), sci_nums)

plt.rcParams['ytick.labelsize'] = 14
fig, ax = plt.subplots()
ax.scatter(range(len(sci_nums)), sci_nums)

This is related to that the larger font size reduces the number of tickslabels. MaxNLocator apparently adjusts the scientific notation depending on the number of ticklabels.
plt.rcParams['ytick.labelsize'] = 13
fig, ax = plt.subplots()
ax.scatter(range(len(sci_nums)), sci_nums)
import matplotlib.ticker as ticker
ax.yaxis.set_major_locator(ticker.MaxNLocator(4))

I dont' quite understand the rule that MaxNLocator uses. Setting 1, 2, 4 or 5 ticklabels results in 1e10. Setting 3, 6, 7, 8, or 9 ticklabels results in 1e9.
Expected outcome
I would expect that changing the number of ticklabels (either directly or via another parameter such as the font size) would not result in a change in the formatting of the scientific notation. In this case, I would expect it to remain 1e9 for all the examples above.
Matplotlib version
- Operating system:
Linux
- Matplotlib version:
2.2.2
- Matplotlib backend (
print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
- Python version:
3.6.6 (conda-forge)
- Jupyter version (if applicable):
jupyterlab=0.34.3, jupyter_core=4.4.0
- Other libraries:
Bug report
Bug summary
MaxNLocatorchanges the scientific notation with different number of tick labels.Code for reproduction
I encountered this unexpected behavior when I changed the y-ticklabel size. Going from size 13 to 14 changes the scientific notation from 1e9 to 1e10, and adds an decimal offset to all the ticklabels.
This is related to that the larger font size reduces the number of tickslabels.
MaxNLocatorapparently adjusts the scientific notation depending on the number of ticklabels.I dont' quite understand the rule that
MaxNLocatoruses. Setting 1, 2, 4 or 5 ticklabels results in1e10. Setting 3, 6, 7, 8, or 9 ticklabels results in1e9.Expected outcome
I would expect that changing the number of ticklabels (either directly or via another parameter such as the font size) would not result in a change in the formatting of the scientific notation. In this case, I would expect it to remain
1e9for all the examples above.Matplotlib version
Linux2.2.2print(matplotlib.get_backend())):module://ipykernel.pylab.backend_inline3.6.6(conda-forge)jupyterlab=0.34.3, jupyter_core=4.4.0