Thanks to visit codestin.com
Credit goes to github.com

Skip to content

text is not clipped by clip_path #8270

Open
@fruchart

Description

@fruchart

Bug report

Bug summary

I expect that a matplotlib.text.Text object should disappear when clipped by setting clip_path=some_path. In practice, the text is still here.

Code for reproduction

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt

plt.figure(figsize=(8,8))
ax = plt.gca()

poly = mpl.patches.Polygon([[1,0], [0,1], [-1,0], [0,-1]], 
                           facecolor="#ddffdd", edgecolor="#00ff00", linewidth=2, alpha=0.5)

ax.add_patch(poly)

# should not be displayed ...
txt_outside = mpl.text.Text(0.75,0.75,"outside :(", clip_on=True, clip_path=poly)
ax.add_artist(txt_outside)

# should be (and is) displayed
txt_inside = mpl.text.Text(0.,0.,"inside :)", clip_on=True, clip_path=poly)
ax.add_artist(txt_inside)

# works perfectly
scatter = plt.scatter(*np.transpose([[0.1,0.1],[0.7,0.7]]), zorder=5, clip_path=poly)

ax.set_xlim(-1,1)
ax.set_ylim(-1,1)
plt.show()

Actual outcome

image

Expected outcome

I would expect the text outside :( not to appear on the image.

Matplotlib version

This happens with matplotlib 2.0.0 with python 3.6.0 (installed with anaconda on linux). It also happens with matplotlib 1.5.3 with python 3.5.2 (same setup).

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Actiontopic: text

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions