Skip to content

indicate_inset rectangles is sensitive to axis-flipping #14670

@clbarnes

Description

@clbarnes

Bug summary

If an axis of the root axes are flipped (e.g. if imshow was used), the inset axes lines may cross over each other. I believe this is because the function looks at the data coordinates of the root axes, but only the figure bounding box of the inset axes.

Code for reproduction

import numpy as np
from PIL import Image

from matplotlib.cbook import get_sample_data
from matplotlib import pyplot as plt

img = np.asarray(Image.open(get_sample_data("logo2.png", False)))

fig, (ax1, ax2) = plt.subplots(1, 2)

ax1.imshow(img)

xmin = 160
ymin = 30
width = 75
height = 60

ax2.imshow(img[ymin:ymin+height, xmin:xmin+width])

ax1.indicate_inset(
    [xmin, ymin, width, height], ax2,
    edgecolor="red"
)

fig.show()

Actual outcome

cross

Expected outcome

Connector lines should not cross

Matplotlib version

3.1.0

  • Operating system: Ubuntu 16.04
  • Matplotlib version: 3.1.0 (pip installed)
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.7.3
  • Other libraries: numpy 1.16.4, pillow 5.3.0

Workaround

Define the inset bounding box with
[xmin, ymax, width, -height]
instead of
[xmin, ymin, width, height]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions