Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zblz opened this issue Aug 5, 2015 · 6 comments
Closed
Milestone

Comments

@zblz
Copy link
Member

zblz commented Aug 5, 2015

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

@tacaswell tacaswell modified the milestones: Color overhaul, proposed next point release Aug 5, 2015
@tacaswell
Copy link
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.

@zblz
Copy link
Member Author

zblz commented Aug 5, 2015

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

@tacaswell
Copy link
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.

@efiring
Copy link
Member

efiring commented Aug 5, 2015

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)

@QuLogic
Copy link
Member

QuLogic commented Dec 12, 2016

Is this fixed by the above PR?

@efiring
Copy link
Member

efiring commented Dec 12, 2016

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

@efiring efiring closed this as completed Dec 12, 2016
@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.1 (next point release) Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants