8000 plt.annotate() FancyArrowPatch does not respect patchA, patchB clipping · Issue #6162 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
plt.annotate() FancyArrowPatch does not respect patchA, patchB clipping #6162
Closed as not planned
@mpharrigan

Description

@mpharrigan
  • python 3.5, matplotlib 1.5.1
  • from miniconda (latest)

Sample code (sorry it's long, but it is self contained). Please look at where I use patchA and patchB with my arrow props in annotate

from matplotlib import pyplot as plt
import itertools

patches = {}
positions = {
        'box 1': [0,0],
        'box 2': [1,0],
        'box 3': [0,1],
}

# Points
for st, (x,y) in positions.items():
    patches[st] = plt.text(x, y, st,
         ha='center', va='center',
         size= 20,
         bbox={'alpha': 0.8},
    )

# Arrows
for r, c in itertools.product(positions.keys(), positions.keys()):
    if r == c:
        continue # skip self-connections

    # Draw arrows
    x1 = positions[c]
    x2 = positions[r]
    plt.annotate('', x2, xytext=x1,
                 arrowprops=dict(
                    arrowstyle='->',
                    connectionstyle='arc3,rad=.2',
                    # THIS IS THE IMPORTANT PART vvv
                    patchA=patches[c],
                    patchB=patches[r],
                    # ^^^^^^^^^^
                 ),
                 zorder=-1,
    )

plt.xlim((-0.5,1.5))
plt.ylim(-0.5, 1.5)
plt.savefig("plot.pdf")
plt.savefig("plot.png")

png

screenshot from 2016-03-15 14 20 21

pdf

screenshot from 2016-03-15 14 20 10

I expect the arrows to be "clipped" by the boxes at the start and end of each arrow. The pdf (and svg) exported version doesn't clip at all. The png version does something weird.

I also tried the "cairo" backend. It also performs no clipping [but changes the bend of the arrows]. Interestingly, the only thing that seems to work is the %matplotlib inline ipython notebook backend. It renders a png exactly as I would expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Actiontopic: arrow

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0