Skip to content

Commit 92ae057

Browse files
committed
Support passing bools to Locator/Formatter
1 parent eb77cbc commit 92ae057

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

proplot/constructor.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -912,17 +912,19 @@ def Locator(locator, *args, index=False, discrete=False, **kwargs):
912912
913913
Parameters
914914
----------
915-
locator : `~matplotlib.ticker.Locator`, str, float, or sequence
915+
locator : `~matplotlib.ticker.Locator`, str, bool, float, or sequence
916916
The locator specification, interpreted as follows:
917917
918918
* If a `~matplotlib.ticker.Locator` instance already, the input
919919
argument is simply returned.
920+
* If ``False``, a `~matplotlib.ticker.NullLocator` is used, and if
921+
``True``, the default `~matplotlib.ticker.AutoLocator` is used.
922+
* If a number, this specifies the *step size* between tick locations.
923+
Returns a `~matplotlib.ticker.MultipleLocator`.
920924
* If a sequence of numbers, these points are ticked. Returns
921925
a `~matplotlib.ticker.FixedLocator` by default,
922926
a `~proplot.ticker.IndexLocator` if `index` is ``True``, or
923927
a `~proplot.ticker.DiscreteLocator` if `discrete` is ``True``.
924-
* If number, this specifies the *step size* between tick locations.
925-
Returns a `~matplotlib.ticker.MultipleLocator`.
926928
927929
Otherwise, `locator` should be a string corresponding to one
928930
of the "registered" locators (see below table). If `locator` is a
@@ -1013,6 +1015,10 @@ def Locator(locator, *args, index=False, discrete=False, **kwargs):
10131015
+ ', '.join(map(repr, LOCATORS))
10141016
+ '.'
10151017
)
1018+
elif locator is True:
1019+
locator = mticker.AutoLocator(*args, **kwargs)
1020+
elif locator is False:
1021+
locator = mticker.NullLocator(*args, **kwargs)
10161022
elif isinstance(locator, Number): # scalar variable
10171023
locator = mticker.MultipleLocator(locator, *args, **kwargs)
10181024
elif np.iterable(locator):
@@ -1033,16 +1039,18 @@ def Formatter(formatter, *args, date=False, index=False, **kwargs):
10331039
10341040
Parameters
10351041
----------
1036-
formatter : `~matplotlib.ticker.Formatter`, str, callable, or sequence
1042+
formatter : `~matplotlib.ticker.Formatter`, str, bool, callable, or sequence
10371043
The formatter specification, interpreted as follows:
10381044
10391045
* If a `~matplotlib.ticker.Formatter` instance already, the input
10401046
argument is simply returned.
1047+
* If ``False``, a `~matplotlib.ticker.NullFormatter` is used, and if
1048+
``True``, the default `~proplot.ticker.AutoFormatter` is used.
1049+
* If a function, the labels will be generated using this function.
1050+
Returns a `~matplotlib.ticker.FuncFormatter`.
10411051
* If sequence of strings, the ticks are labeled with these strings.
10421052
Returns a `~matplotlib.ticker.FixedFormatter` by default or
10431053
an `~proplot.ticker.IndexFormatter` if `index` is ``True``.
1044-
* If a function, the labels will be generated using this function.
1045-
Returns a `~matplotlib.ticker.FuncFormatter`.
10461054
* If a string containing ``{x}`` or ``{x:...}``, ticks will be
10471055
formatted by calling ``string.format(x=number)``. Returns
10481056
a `~matplotlib.ticker.StrMethodFormatter`.
@@ -1149,9 +1157,12 @@ def Formatter(formatter, *args, date=False, index=False, **kwargs):
11491157
+ ', '.join(map(repr, FORMATTERS))
11501158
+ '.'
11511159
)
1160+
elif formatter is True:
1161+
formatter = pticker.AutoFormatter(*args, **kwargs)
1162+
elif formatter is False:
1163+
formatter = mticker.NullFormatter(*args, **kwargs)
11521164
elif np.iterable(formatter):
1153-
cls = pticker.IndexFormatter if index else mticker.FixedFormatter
1154-
formatter = cls(formatter)
1165+
formatter = (mticker.FixedFormatter, pticker.IndexFormatter)[index](formatter)
11551166
elif callable(formatter):
11561167
formatter = mticker.FuncFormatter(formatter, *args, **kwargs)
11571168
else:

0 commit comments

Comments
 (0)