First Jupyter cell:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
%matplotlib notebook
plt.figure()
plt.plot((1,2,3))
labels = [item.get_text() for item in plt.gca().get_xticklabels()]
print("Labels are: {}".format(labels))
The ouput is (besides the chart):
Labels are: ['', '', '', '', '', '', '', '', '', '', '']
Now, in another cell, if I run the same code:
labels = [item.get_text() for item in plt.gca().get_xticklabels()]
print("Labels are: {}".format(labels))
The ouput is:
Labels are: ['', '0.00', '0.25', '0.50', '0.75', '1.00', '1.25', '1.50', '1.75', '2.00', '']
Why the same code, referencing the same Axes, returns different results?
pltobject has changed when the plot is rendered. Some internal magic in matplotlib, perhaps.