FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add additional minor labels in log axis with a span less than two decades · Issue #4867 · matplotlib/matplotlib · GitHub

Repository navigation

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

Closed

Description

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

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))

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]))

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())

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)

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].

Activity

  1. modified the milestones: , on Aug 5, 2015
  2. tacaswell commented on Aug 5, 2015

    Member

    I am somewhat ambivalent on this as I am not convinced of the utility of log scaled axis with less than 2 decades of data.

  3. zblz commented on Aug 5, 2015

    MemberAuthor

    In my field (high energy astrophysics) they are extremely common: the
    gamma-ray photon spectra of an astrophysical source will almost always
    follow a powerlaw behaviour, and the energy detection band for a single
    instrument is rarely larger than two decades (often less than one), so the
    plotted spectra from a single instrument are always like this. It might be
    a corner case, but I brought it up as it comes up very often in my use of
    matplotlib.

    This would be useful for the gammapy and
    naima packages, which deal with gamma-ray spectra
    and use matplotlib for plotting.

    2015-08-05 14:46 GMT+01:00 Thomas A Caswell notifications@github.com:

    I am somewhat ambivalent on this as I am not convinced of the utility of
    log scaled axis with less than 2 decades of data.

    —
    Reply to this email directly or view it on GitHub
    #4867 (comment)
    .

  4. tacaswell commented on Aug 5, 2015

    Member

    Fair enough. I come from a soft-matter physics background where we are looking for power laws in noisy data, with less than 2 decades just about any powerlaw can be made to fit, hence my skepticism.

  5. efiring commented on Aug 5, 2015

    Member

    Another case where it would be nice to have labels for a short span of
    a log scale is when one zooms in on a feature in a spectrum.

    On 8/5/15, Thomas A Caswell notifications@github.com wrote:

    Fair enough. I come from a soft-matter physics background where we are
    looking for power laws in noisy data, with less than 2 decades just about
    any powerlaw can be made to fit, hence my skepticism.


    Reply to this email directly or view it on GitHub:
    #4867 (comment)

  6. QuLogic commented on Dec 12, 2016

    Member

    Is this fixed by the above PR?

  7. efiring commented on Dec 12, 2016

    Member

    It was, but that was reverted by #7000, and then a modified version was restored by #7419.

  8. modified the milestones: , on Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL