Closed
Description
Bug summary
The ScalarFormatter class takes an argument useOffset, either True, which will determine an automatic offset, False, which disables an offset or an numeric value, which is the used as an offset.
Since in python 1 == True --> True, trying to pass a numeric offset value of 1 just enables the automatic offset.
https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.ScalarFormatter
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter
# Sample data
x = np.linspace(0, 10, 100)
y = np.linspace(0.999, 1.001, 100)
# Create the plot
fig, ax = plt.subplots()
ax.plot(x, y)
formatter = ScalarFormatter()
formatter.set_useOffset(1)
# identical to formatter = ScalarFormatter(useOffset=1)
ax.yaxis.set_major_formatter(formatter)
plt.show()
Actual outcome
Expected outcome
The y-Axis should be centered around zero, the expected offset of 1 is not used
Additional information
Happens only for useOffset = 1.
If the y values are changed (i.e. y = np.linspace(0.99999, 1.00001, 100)), the automatic offset actually uses an offset of 1, so the bug is not obvious then.
Operating system
Win 11
Matplotlib Version
3.7.2
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
No response
Jupyter version
6.5.4
Installation
conda