Skip to content

Replacing a tile of a tiled figure leaves the old axes on the figure #594

Description

@SimonHeybrock

Assigning to a cell that is already occupied leaves the previous tile's axes on the figure. Tiled.__setitem__ unconditionally calls self.fig.add_subplot(self.gs[inds]), so the replaced axes is never removed and stays visible, drawn underneath the new one.

Reproduction

import plopp as pp
from plopp.data.testing import data_array

da = data_array(ndim=1)
t = pp.tiled(1, 1)
t[0, 0] = da.plot()
t[0, 0] = (da * 5.0).plot()

len(t.fig.get_axes())                                  # 2
[a.get_visible() for a in t.fig.get_axes()]            # [True, True]
[a.get_ylim() for a in t.fig.get_axes()]               # [(-1.1, 1.1), (-5.48, 5.5)]

Both axes render on top of each other. Since their ranges differ, the result carries two interleaved sets of tick labels and a doubled axis label:

overlapping axes

Composition replays the superseded tile

_history keeps every assignment, and __add__/__truediv__ replay all of them into the new figure, so the discarded tile is carried into the combined figure as well:

combined = t + da.plot()
combined.nrows, combined.ncols        # 1, 2
len(combined.fig.get_axes())          # 3, where one axes per cell would be 2

Expected

Replacing a tile should leave a single axes in that cell, and composition should replay only the tiles the figure currently holds.

Notes

Fixing this means deciding what replacement should mean. Removing the stale axes and dropping the superseded _history entry is the obvious reading, but it interacts with axis sharing: Matplotlib provides no way to un-share axes, so a replaced tile cannot be detached from the tiles it was joined to. The shared-axes work in the tiled figures PR therefore rejects replacement outright when sharing is enabled, which sidesteps rather than solves the underlying issue.

Found while working on axis sharing for tiled figures; present on main and unrelated to that branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions