Skip to content

Add additional minor labels in log axis with a span less than two decades #4867

@zblz

Description

@zblz

For plots with log axis that have limits of the order or less than two decades, only one label is shown:
log_labels

Which does not give a very good idea of the values of the x axis. Adding labels to the minor ticks results in a mess, including non-helpful labels such as 10^{4.30}:

ax.xaxis.set_minor_formatter(ticker.LogFormatterMathtext(labelOnlyBase=False))

log_labels_minor_logformattermathtext

And limiting them at [2,5]*base**i results in losing all other minor ticks:

ax.xaxis.set_minor_locator(ticker.LogLocator(subs=[2,5]))

log_labels_minor_at_125_logformattermathtext

The decimals in the exponent can be resolved using LogFormatter, but it is not a nice representation for axis and requires changing the major formatter to match:

ax.xaxis.set_minor_formatter(ticker.LogFormatter(labelOnlyBase=False))
ax.xaxis.set_major_formatter(ticker.LogFormatter())

log_labels_minor_at_125_logformatter

Finally, the only way to get them in a consistent manner with the major tick labels, while preserving all minor ticks, is to set them manually, which is far from ideal:

ax.xaxis.set_ticklabels([r'$2\times10^4$','','',r'$5\times10^4$','','','','', 
        r'$2\times 10^4$','','',r'$5\times10^4$','','','','',
        r'$2\times 10^5$','','',r'$5\times10^5$','','','','',
        ],minor=True)

log_labels_minor_at_125_manual_labels

I think that there should be a LogFormatterMathtext with a subs options like the locator, and an option to factors instead of decimal exponents. I will take a look at the LogFormatterMathtext and try to modify it in the following days. If it looks good, I would propose to switch to it automatically for axis spanning less than two decades.

Note that this issue has been reported in a stackoverflow question where a custom formatter is proposed as an answer.
This is somewhat related to the issue #4730 because the lack of labels is particularly noticeable when the axis is around 0.1,1,10, where it would make a lot of sense to have labels at [0.1,0.2,2,5,20,50].

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy