Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/api/next_api_changes/deprecations/31416-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Formatter attributes
~~~~~~~~~~~~~~~~~~~~

These following attributes are considered internal and users should not have a need to access them:

- `.ScalarFormatter`: ``orderOfMagnitude`` and ``format``
- `.ConciseDateFormatter`: ``offset_format``
- `.Formatter`: ``locs``
6 changes: 5 additions & 1 deletion lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ class ConciseDateFormatter(ticker.Formatter):
"""

offset_string = _api.deprecate_privatize_attribute(
"3.11", alternative="get_offset()"
)

def __init__(self, locator, tz=None, formats=None, offset_formats=None,
zero_formats=None, show_offset=True, *, usetex=None):
"""
Expand Down Expand Up @@ -719,7 +723,7 @@ def __init__(self, locator, tz=None, formats=None, offset_formats=None,
'%Y-%b-%d',
'%Y-%b-%d',
'%Y-%b-%d %H:%M']
self.offset_string = ''
self._offset_string = ''
self.show_offset = show_offset
self._usetex = mpl._val_or_rc(usetex, 'text.usetex')

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/testing/jpl_units/UnitDblFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UnitDblFormatter(ticker.ScalarFormatter):

def __call__(self, x, pos=None):
# docstring inherited
if len(self.locs) == 0:
if len(self._locs) == 0:
return ''
else:
return f'{x:.12}'
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ def test_scilimits(self, sci_type, scilimits, lim, orderOfMag, fewticks):
ax.yaxis.set_major_locator(mticker.MaxNLocator(4))

tmp_form.set_locs(ax.yaxis.get_majorticklocs())
assert orderOfMag == tmp_form.orderOfMagnitude
assert orderOfMag == tmp_form._orderOfMagnitude

@pytest.mark.parametrize('value, expected', format_data)
def test_format_data(self, value, expected):
Expand Down
15 changes: 10 additions & 5 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ class Formatter(TickHelper):
"""
# some classes want to see all the locs to help format
# individual ones
locs = []
_locs = []

locs = _api.deprecate_privatize_attribute("3.11")

def __call__(self, x, pos=None):
"""
Expand Down Expand Up @@ -250,7 +252,7 @@ def set_locs(self, locs):
This method is called before computing the tick labels because some
formatters need to know all tick locations to do so.
"""
self.locs = locs
self._locs = locs

@staticmethod
def fix_minus(s):
Expand Down Expand Up @@ -458,15 +460,18 @@ class ScalarFormatter(Formatter):

"""

orderOfMagnitude = _api.deprecate_privatize_attribute("3.11")
format = _api.deprecate_privatize_attribute("3.11")

def __init__(self, useOffset=None, useMathText=None, useLocale=None, *,
usetex=None):
useOffset = mpl._val_or_rc(useOffset, 'axes.formatter.useoffset')
self._offset_threshold = mpl.rcParams['axes.formatter.offset_threshold']
self.set_useOffset(useOffset)
self.set_usetex(usetex)
self.set_useMathText(useMathText)
self.orderOfMagnitude = 0
self.format = ''
self._orderOfMagnitude = 0
self._format = ''
self._scientific = True
self._powerlimits = mpl.rcParams['axes.formatter.limits']
self.set_useLocale(useLocale)
Expand Down Expand Up @@ -1446,7 +1451,7 @@ def __call__(self, x, pos=None):
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
if abs(xp) < 1e-8:
xp = 0
return self._format_maybe_minus_and_locale(self.format, xp)
return self._format_maybe_minus_and_locale(self._format, xp)

def set_locs(self, locs):
# docstring inherited
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/ticker.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TickHelper:

class Formatter(TickHelper):
locs: list[float]
_locs: list[float]
def __call__(self, x: float, pos: int | None = ...) -> str: ...
def format_ticks(self, values: list[float]) -> list[str]: ...
def format_data(self, value: float) -> str: ...
Expand Down Expand Up @@ -58,7 +59,9 @@ class StrMethodFormatter(Formatter):

class ScalarFormatter(Formatter):
orderOfMagnitude: int
_orderOfMagnitude: int
format: str
_format: str
def __init__(
self,
useOffset: bool | float | None = ...,
Expand Down
Loading