Skip to content

set_ticks_position to non-default position, sets all tick texts to empty string #3012

Closed
@olgabot

Description

@olgabot

When setting yticklabels or xticklabels and then setting the position, the tick._text field gets cleared.

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
ax.plot([0, 1], [0, 1])

ax.set_yticklabels(list('asdfgh'))

print('before')
print('ax.get_yticklabels', map(lambda x: x._text, ax.get_yticklabels()))

ax.yaxis.set_ticks_position('right')

print('\nafter')
print('ax.get_yticklabels', map(lambda x: x._text, ax.get_yticklabels()))
print('ax.get_ymajorticklabels', map(lambda x: x._text, ax.get_ymajorticklabels()))
print('ax.get_yminorticklabels', map(lambda x: x._text, ax.get_yminorticklabels()))

results in


before
('ax.get_yticklabels', [u'a', u's', u'd', u'f', u'g', u'h'])

after
('ax.get_yticklabels', [u'', u'', u'', u'', u'', u''])
('ax.get_ymajorticklabels', [u'', u'', u'', u'', u'', u''])
('ax.get_yminorticklabels', [])

This is true for either x- or y-ticklabels

However, the behavior is as expected when the position is set first, then the ticklabel values are set:

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
ax.plot([0, 1], [0, 1])

ax.yaxis.set_ticks_position('right')


print('before')
print('ax.get_yticklabels', map(lambda x: x._text, ax.get_yticklabels()))

ax.set_yticklabels(list('asdfgh'))

print('\nafter')
print('ax.get_yticklabels', map(lambda x: x._text, ax.get_yticklabels()))
print('ax.get_ymajorticklabels', map(lambda x: x._text, ax.get_ymajorticklabels()))
print('ax.get_yminorticklabels', map(lambda x: x._text, ax.get_yminorticklabels()))

results in:


before
('ax.get_yticklabels', [u'', u'', u'', u'', u'', u''])

after
('ax.get_yticklabels', [u'a', u's', u'd', u'f', u'g', u'h'])
('ax.get_ymajorticklabels', [u'a', u's', u'd', u'f', u'g', u'h'])
('ax.get_yminorticklabels', [])

Full example, plus pip list:
http://nbviewer.ipython.org/gist/anonymous/11332415

Any ideas what may be going on? From delving into the code, I'm taking a wild guess that it's something in Tick._apply_params that may be going awry, but really not sure.

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