What do I pass to the transform
argument of SymmetricalLogLocator()
?
https://matplotlib.org/3.1.0/api/ticker_api.html#matplotlib.ticker.SymmetricalLogLocator
I’m trying to use this in a contourf()
.
What do I pass to the transform
argument of SymmetricalLogLocator()
?
https://matplotlib.org/3.1.0/api/ticker_api.html#matplotlib.ticker.SymmetricalLogLocator
I’m trying to use this in a contourf()
.
You want to pass a SymmetricalLogTransform
object, as defined in the matplotlib.scale class file into the transform=
argument.
According to the code for the ticker class, only the base
and linthresh
values from this object are passed in to the SymmetricalLogLocator
:
if transform is not None:
self._base = transform.base
self._linthresh = transform.linthresh
Alternatively, you can avoid using the transform
parameter and just pass base=
and linthresh=
parameter settings individually.
elif linthresh is not None and base is not None:
self._base = base
self._linthresh = linthresh
If you don’t do either of the above the code raises the following ValueError
else:
raise ValueError("Either transform, or both linthresh "
"and base, must be provided.")
base
parameter
This defines the base of the log scaling (placing a major tick every base**i, where i is an integer)
linthresh
parameter
This defines the range within which the plot is treated as linear (to avoid having the plot go to infinity around zero). Further discussion of this parameter can be found HERE.
By way of example, try this example code, which uses contourf()
and LogLocator()
, and simply replace the usage of LogLocator()
with e.g.
SymmetricalLogLocator(base=10, linthresh=0.1)
Alternatively, to supply a transform=
parameter, you would need to use the following import
from matplotlib.scale import SymmetricalLogTransform
instantiate a SymmetricalLogTransform
object with base
, linthresh
and linscale
arguments respectively
trans = SymmetricalLogTransform(10, 0.1, 1)
(NOTE: any numerical value for linscale
will do here as it’s not used by the SymmetricalLogLocator
)
and then change your usage of SymmetricalLogLocator()
to use the transform=
argument, supplying it with yourSymmetricalLogTransform
instance (trans
)
SymmetricalLogLocator(transform=trans)
Admittedly not a very interesting example but it hopefully proves the principle.
Hope the helps
Laurence
FYI
I’ve expanded the docstrings for the SymmetricalLogLocator object constructor to include brief details of parameters required as discussed above so that future users have a little more information to go on.
A pull request has been issued for review (#16342).
Perhaps you could help the matplotlib project by providing an opinion regarding whether this would have sufficed in your situation? You can find details of the proposed additions to the documentation here (click on “files changed” for diff details):