scipp / scipp/plopp

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

Open
#594 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
12
Forks
6
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Tiled.setitem and inspect how it calls add_subplot and records assignments in _history. Then trace add and truediv to see how assignments are replayed, and review the tiled-figures axis-sharing behavior. Done means replacement leaves one axes per cell and composition excludes superseded tiles, while preserving the documented sharing constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.