Skip to content

Incorrect labels returned with custom formatter and locator #9397

@astrofrog

Description

@astrofrog

In the following example I am getting back the wrong labels from ax.xaxis.get_ticklabels:

import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter, MaxNLocator

ax = plt.subplot(1,1,1)

def formatter_func(pos, *args):
    return 'a' if pos == 1 else ''

ax.figure.canvas.draw()
print([tick.get_text() for tick in ax.xaxis.get_ticklabels()])

ax.xaxis.set_major_formatter(FuncFormatter(formatter_func))
ax.xaxis.set_major_locator(MaxNLocator(10, integer=True))

ax.set_xlim(-0.5, 2.5)

ax.figure.canvas.draw()
print([tick.get_text() for tick in ax.xaxis.get_ticklabels()])

This gives:

['0.0', '0.2', '0.4', '0.6', '0.8', '1.0']
['0.0', '', 'a', '', '0.8']

whereas I expected:

['0.0', '0.2', '0.4', '0.6', '0.8', '1.0']
['', '', 'a', '', '']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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