matplotlib / matplotlib/matplotlib

inverse transform break chaining

Open
#10,741 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Difficulty: Hard keep New feature topic: transforms and scales
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Bug report

**Bug summary**

Transform chaining seems to not be possible in some cases. As an example
```
tr = ax.transAxes - ax.transData + ax.transData
```
gives a different result than
```
tr = ax.transAxes
```
although those are linear transformations, which can easily be inverted, so one would expect
```
A + B^-1 + B == A
```
The following example shows that this is not the case.

**Code for reproduction**

The code should create a red and a green line from [0,0] to [1,1] in axes cooridinates. Yet the red line is somehow fixed to its initial prosition and forgets about its transform.

```
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

# apply transform A + B^-1 + B
# this should equal A
tr = ax.transAxes - ax.transData
trinv = ax.transData
line = plt.Line2D([0,1],[0,1],transform=tr+trinv, color="crimson")
ax.add_line(line)

# apply transform A
line2 = plt.Line2D([0,1],[0,1],transform=ax.transAxes, color="limegreen")
ax.add_line(line2)

ax.set_ylim(.1,1.1)

plt.show()
```

**Actual outcome**

![image](https://user-images.githubusercontent.com/23121882/37214723-270b2396-23b6-11e8-8ee2-4e174c0077b5.png)

**Expected outcome**

A plot with red and green line overlapping.

Now it may well be that I'm completely misunderstanding the transform chaining in which case it would probably be good to update the documentation.

**Matplotlib version**

* Operating system: Windows 8.1
* Matplotlib version: 2.2
* Matplotlib backend: Qt4Agg as well as TkAgg
* Python version: 2.7.10

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 by running the provided Python reproduction with ax.transAxes, ax.transData, and Line2D, then inspect the transform-chaining behavior involved in A + B^-1 + B. Compare the red and green lines after ax.set_ylim(.1, 1.1). Done means the chained transform matches ax.transAxes, or the transform documentation clearly explains the expected behavior.

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
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.