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

get_ticklabels returns '' in ipython/python interpreter #6638

Closed
story645 opened this issue Jun 24, 2016 · 3 comments
Closed

get_ticklabels returns '' in ipython/python interpreter #6638

story645 opened this issue Jun 24, 2016 · 3 comments

Comments

@story645
Copy link
Member

story645 commented Jun 24, 2016

ax.get_xticklabels & ax.get_yticklabels is returning a list of empty strings when I run the code via script/ipython interpreter, but works as expected (returns list of ticklabels) when called in ipython notebook. This makes me think it's a backend bug, but I'm mystified.

Env:

Python 3.5.1 |Continuum Analytics, Inc.| (default, Dec  7 2015, 11:24:55) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin

matplotlib version:

  • 1.5.1 (installed in different anaconda env to verify not a beta bug)
  • 2.0.0b1.post1730.dev0+gfdce976 (last pulled in a few hours ago)

This will reproduce it: (I use agg here, but MacOSX is exhibiting the same behavior)

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot([1,2,3])
print(list(l.get_text() for l in ax.get_xticklabels()))
print(list(l.get_text() for l in ax.get_yticklabels()))

Both print statements yield ['', '', '', '', ''] when they should be [0, 1, 2] & [1, 2, 3]

@story645 story645 changed the title get_ticklabels returns "" in ipython/python interpreter get_ticklabels returns '' in ipython/python interpreter Jun 24, 2016
@Tillsten
Copy link
Contributor

Afaik the ticks will be popluated at draw time.

@story645
Copy link
Member Author

story645 commented Jun 24, 2016

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot([1,2,3])
plt.draw()

works, but still won't work with 'MacOSX' backend,

@partizanos
Copy link

partizanos commented Oct 1, 2020

@story645
You can use instead
[i.get_text() for i in plt.xticks()[1]]

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