8000 Incorrect labels returned with custom formatter and locator · Issue #9397 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Incorrect labels returned with custom formatter and locator #9397
Closed
@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

      0