Skip to content

AttributeError: 'NoneType' object has no attribute 'canvas' #5663

Closed
@dessant

Description

@dessant

Removing an ax created with twinx/twiny and then adding a new one with a plot, or just setting xlim/ylim for it triggers the crash (twinx -> xlim, twiny -> ylim).

import matplotlib
matplotlib.use('TkAgg')  # same with 'agg'

import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(111)

ax2 = ax1.twinx()
ax2.remove()

ax3 = fig.add_subplot(111)
ax3.set_xlim([1, 5])

plt.show()
Traceback (most recent call last):
  File "E:\dev\prs\main\test2.py", line 13, in <module>
    ax3.set_xlim([1, 5])
  File "e:\dev\envs\py34_x86\Python\lib\site-packages\matplotlib\axes\_base.py", line 2783, in set_xlim
    other.figure.canvas is not None):
AttributeError: 'NoneType' object has no attribute 'canvas'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions