Getting empty tick labels before showing a plot in Matplotlib
<p>I'm experiencing a similar issue to the one reported <a href="https://stackoverflow.com/questions/32700935/get-xticklabels-contains-empty-text-instances">here</a>. I don't understand why the tick label text is an empty string:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,2*np.pi,100)
y = np.sin(x)**2

fig, ax = plt.subplots()
ax.plot(x,y)

labels = ax.get_xticklabels()
for label in labels:
    print(label)

plt.show()
</code></pre>

<p>Output:</p>

<pre><code>Text(0,0,'')
Text(0,0,'')
Text(0,0,'')
Text(0,0,'')
Text(0,0,'')
Text(0,0,'')
Text(0,0,'')
Text(0,0,'')
</code></pre>

<p>I get the same result with <code>ax.xaxis.get_ticklabels()</code> but the plotted graph shows eight labelled ticks on the x-axis when saved or shown. However, if I ask for the labels <em>after</em> I show the plot, then the <code>labels</code> list is properly populated. Of course, it's a bit late to do anything about changing them then.</p>

<pre><code>fig, ax = plt.subplots()
ax.plot(x,y)
plt.show()

labels = ax.get_xticklabels()
for label in labels:
    print(label)
</code></pre>

<p>Output:</p>

<pre><code>Text(0,0,'0')
Text(1,0,'1')
Text(2,0,'2')
Text(3,0,'3')
Text(4,0,'4')
Text(5,0,'5')
Text(6,0,'6')
Text(7,0,'7')
</code></pre>

<p>Why does this happen (Mac OS X Yosemite, Matplotlib 1.5.1) and how can I get my labels <em>before</em> I show or save my plot?</p>