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

weird bug when using custom formatter; tick labels overlapping · Issue #8401 · matplotlib/matplotlib · GitHub

Repository navigation

weird bug when using custom formatter; tick labels overlapping #8401

Closed

Description

Bug report

Bug summary

I use a custom tick formatter in my plot. It worked great with an older version of matplotlib but I just upgraded to 2.0 and I see overlapping tickmark labels (the default labels are still there):

Code for reproduction

import numpy as np
import matplotlib
import matplotlib.pyplot as plt


class MyLogFormatter(matplotlib.ticker.LogFormatter):
    def __call__(self, x, pos=None):
        e = np.floor(np.log10(x))
        m = x/(10**e)
        if x < 0.01:
            return '%de%d' % (round(m), e)
        elif x < 1:
            return '%.2f' % x
        elif x < 10:
            return '%.1f' % x
        elif x < 1000:
            return '%.0f' % x
        else:
            return '%de%d' % (round(m), e)
    @staticmethod
    def ticks(xmin, xmax):
        ndecades = np.ceil(np.log10(xmax/xmin))
        if ndecades > 6:
            mantissas = [1]
        elif ndecades > 3:
            mantissas = [1,3]
        else:
            mantissas = [1,2,5]
        roundnumbers = (10**np.arange(np.floor(np.log10(xmin)), np.ceil(np.log10(xmax)))*np.atleast_2d(mantissas).T).T.flatten()
        return np.hstack((xmin, [x for x in roundnumbers if xmin*1.25 < x < 0.8*xmax], xmax))        

data = 0
for k in xrange(4):
    data += np.random.randint(6, size=100000)
    
count,edges = np.histogram(data,10)
x = 100 * (1.1 ** edges)

fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(1,1,1,xscale='log')
ax.bar(x[:-1], count, width=x[1:] - x[:-1], color='red',edgecolor='black',align='edge')
xmin = min(x)
xmax = max(x)
LF = MyLogFormatter(labelOnlyBase=False)
ax.set_xticks(LF.ticks(xmin, xmax))
ax.xaxis.set_major_formatter(LF)     

Actual outcome

  • The output produced by the above code, which may be a screenshot, console output, etc.

Expected outcome

previous version was Matplotlib 1.5.1
(can't post right now, I will have to downgrade my anaconda version)

Matplotlib version

  • Matplotlib 2.0
    Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32

Activity

  1. jason-s commented on Mar 29, 2017

    Author

    Oh, never mind, adding this line suppresses the minor tick labels:

    ax.xaxis.set_minor_formatter(matplotlib.ticker.NullFormatter())

    Incidentally, what changed around minor tick labels?

  2. tacaswell commented on Mar 30, 2017

    Member

    See http://matplotlib.org/users/dflt_style_changes.html#logformatter-labeling-of-minor-ticks for documentation of the changes to minor ticks.

    We made it better by default, but seem to have broken a bunch of people who were doing custom things.

  3. phobson commented on Mar 30, 2017

    Member

    duplicate of #8386

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL