[Matplotlib-devel] Easier tick formatters

Todd toddrjen at gmail.com
Thu Mar 5 09:57:07 EST 2020


Okay, so then it would be `None` to reset, `''` for `NullFormatter`, a
callable for `FuncFormatter`, and a string for `StrMethodFormatter`.  That
avoids the complexity of determining what exactly constitutes a "sequence"
for the purposes of IndexFormatter/FixedFormatter.

On Wed, Mar 4, 2020 at 10:15 PM Thomas Caswell <tcaswell at gmail.com> wrote:

> Interesting, I am weakly in favor of this.
>
> I am normally very hesitant about adopting heuristics, but these seem well
> defined.  If we do this, we should drop the last rule as IndexFormatter is
> scheduled to be deprecated in in 3.3 and is a bit problematic in other ways.
>
> I don't see any back-compatibility concerns (as none of those inputs work
> now).
>
> Tom
>
> On Wed, Mar 4, 2020 at 10:03 PM Todd <toddrjen at gmail.com> wrote:
>
>> 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?
>> _______________________________________________
>> Matplotlib-devel mailing list
>> Matplotlib-devel at python.org
>> https://mail.python.org/mailman/listinfo/matplotlib-devel
>>
>
>
> --
> Thomas Caswell
> tcaswell at gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20200305/28dc57f7/attachment-0001.html>


More information about the Matplotlib-devel mailing list