Skip to content

Calling savefig() changes the return value of ax.get_xticklabels() #6800

Closed
@levitsky

Description

@levitsky

matplotlib 1.5.1 on Linux, installed from binary package, both on Python 3.5.2 and 2.7.12.

Here is the code:

import pylab
f, axes = pylab.subplots(2, sharex=True, sharey=True)
for ax in axes:
    ax.plot(range(100))
for ax in axes:
    print([x.get_text() for x in ax.get_xticklabels()])
print('----')
pylab.savefig('/tmp/tempfig.png')
for ax in axes:
    print([x.get_text() for x in ax.get_xticklabels()])

The output is:

['', '', '', '', '', '']
['', '', '', '', '', '']
----
['0', '20', '40', '60', '80', '100']
['0', '20', '40', '60', '80', '100']

If I comment out the call to savefig(), I get

['', '', '', '', '', '']
['', '', '', '', '', '']
----
['', '', '', '', '', '']
['', '', '', '', '', '']

The tick labels (which I am trying to get) are seen in the figure:

image

Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions