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

Log scale tick labels are overlapping #6549

Closed
mxmlnkn opened this issue Jun 7, 2016 · 6 comments
Closed

Log scale tick labels are overlapping #6549

mxmlnkn opened this issue Jun 7, 2016 · 6 comments
Assignees
Milestone

Comments

@mxmlnkn
Copy link

mxmlnkn commented Jun 7, 2016

  • Linux hypatia-pc 4.5.0-1-amd64 Fix autofmt_xdate() when using in conjunction with twinx() #1 SMP Debian 4.5.1-1 (2016-04-14) x86_64 GNU/Linux

    lsb_release -a
        No LSB modules are available.
        Distributor ID: Debian
        Description:    Debian GNU/Linux 8.4 (jessie)
        Release:    8.4
        Codename:   jessie
    
  • matplotlib 1.5.2~rc2-1

  • Python 2.7.11+

  • installed using: sudo apt-get install -t sid python matplotlibg

Here is an example where the problem appears:

from matplotlib.pyplot import *
figure( figsize=[4,3] )
subplot( 111, xscale='log' )
plot( [1e-20,1e5], [1e-16,10] )
show()

For lack of time the following image wasn't reproduced with the above example, but came from another problem:
loglabel-bugfix-reduced

The right side shows the problem and the left side is my workaround which calculates some distance for a given amount of labels I want (here I wanted 5 labels or less). So it set every exponent, but every sixth integer exponent, i.e. -16,-10,-4.

It would be cool if it was fully automatic like with linear scales.

@mxmlnkn
Copy link
Author

mxmlnkn commented Jun 7, 2016

This bug also happens with the linear scale:

from matplotlib.pyplot import *
figure( figsize=[4,3] )
plot( [0.1310,0.1315], [0,1] )
tight_layout()
show()

label-overlapping

Note that without tight_layout the +1.309e1 won't be inside the canvas:
label-overlapping-no-tight_layout
I would say this is still another bug.

I would just be nice if the formatter could do something like:

while exists i: labelpos[i] + width( text(label[i]) ) + spacing >= labelpos[i+1]:
    reduce number of labels by one

@tacaswell
Copy link
Member

Can you try the 2.0.0b1 which implements something like that?

@anntzer
Copy link
Contributor

anntzer commented Jun 8, 2016

2.0 solves the problem for linear scale, but not for log-scale (the original issue): the LogLocator class does not use the ticks-limiting logic present in MaxNLocator. (Apparently neither do SymmetricalLogLocator or LogitLocator.)

@mxmlnkn
Copy link
Author

mxmlnkn commented Jun 8, 2016

@tacaswell : The only difference in 2.0b is that the default label font size is smaller (or maybe it just uses a different backend), resulting in the above linear scale example to actually work. But adding some 0s, I can still reproduce the problem even with linear scales, unlike @anntzer said.

logarithmic scale (minimal example from 1st post):
log-scale
linear scale (minimal example from 2nd post):
lin-scale-2 0
linear scale even more extreme (This may be an extreme example, but it could still be solved by reducing the number of tick labels by one):
lin-scale-2 0-even-smaller

Above done with:

from matplotlib.pyplot import *
figure( figsize=[4,3] )
plot( [0.131000,0.131005], [0,1] )
tight_layout()
show()

print matplotlib.__version__
    2.0.0b1

@anntzer
Copy link
Contributor

anntzer commented Jun 8, 2016

Indeed, 2.0 just uses a heuristic where the aspect ratio of an xlabel is no more than 1x3 (by the way, I just realized that this would be way too pessimistic (too optimistic for ylabels) if the labels are rotated...).

As discussed in #5494, it is not so easy to handle this automatically because the tick labels are rendered after the tick positions are selected.

@tacaswell tacaswell added this to the 2.0 (style change major release) milestone Aug 30, 2016
@tacaswell
Copy link
Member

Linked with #7001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants