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

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

Closed
olgabot opened this issue Apr 26, 2014 · 3 comments
Closed
Milestone

Comments

@olgabot
Copy link
Contributor

olgabot commented Apr 26, 2014

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.

@tacaswell
Copy link
Member

I strongly suspect that this is the same issue as #2941 which results from a cla an the axis object when you move the axis location.

@tacaswell tacaswell added this to the v1.4.0 milestone May 16, 2014
@tacaswell tacaswell modified the milestones: v1.4.x, v1.4.0 May 28, 2014
@efiring
Copy link
Member

efiring commented Jun 1, 2014

It's not a bug, it's a feature...
The axis actually keeps two sets of ticks and labels, one for each side. When you call set_ticks_position('right') you are just telling the axis to hide the left-hand ticks and show the right-hand ticks. Since your call to set_yticklabels() was made when the left-hand side was active, it set only the left-hand labels. In fact, if at the end of your example you call `set_ticks_position('left') and print, you will see that the labels are still there.
It's a bit confusing. I suspect that if we were starting from scratch we could now design a simpler and more transparent API; but given where we are, I don't see any obvious change to make related to this issue.

@efiring
Copy link
Member

efiring commented Jun 1, 2014

#2941 is different; it is addressed by #3104.

@efiring efiring closed this as completed Jun 1, 2014
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

3 participants