[Matplotlib-devel] Easier tick formatters

Todd toddrjen at gmail.com
Wed Mar 4 22:03:29 EST 2020


Currently setting up the tick formatting on matplotlib requires you to
import a formatter from the ticker module, create an instance of that
formatter, then pass that to the axis.  This makes sense for complicated
formatting.  However, there are some obvious cases where we can probably
infer the type of formatting someone wants to do if we are just given the
formatter content.  For example

   * '' is probably going to be the null formatter
   * A callable, besides a formatter instance, is probably going to be a
function formatter
   * A sequence or numpy array is probably going to be an index or fixed
formatter, depending on the locator
   * Any other string is probably going to be a format string formatter or
string method formatter.

So I think we could allow the `set_major_formatter` and `set_minor_formatter`
to take certain sorts of inputs and create the formatter automatically for
the user, making such cases much, much easier.  Specifically, I propose the
following inputs be accepted:

   * `None` sets it to the default formatter
   * A callable (besides a formatter instance) is set to be a FuncFormatter
   * An empty string, `''`, is set to be a NullFormatter
   * Any other string is a StrMethodFormatter
   * An abc.collections.Sequence subclass or numpy ndarray subclass is an
IndexFormatter, unless the axis is using a FixedLocator in which case it is
a FixedLocator.  We could restrict this to just lists and numpy arrays only.

Any thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20200304/e39e8faf/attachment-0001.html>


More information about the Matplotlib-devel mailing list