8000 Fixed hatch clipping. by pelson · Pull Request #2003 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fixed hatch clipping. #2003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't overwrite unit_circle vertices -- causes problems for many othe…
…r tests
  • Loading branch information
mdboom committed May 14, 2013
commit c0e2e48249f81ffd7adeffe03661ec95f6d4a4d0
42 changes: 22 additions & 20 deletions lib/matplotlib/tests/test_artist.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@
def test_patch_transform_of_none():
# tests the behaviour of patches added to an Axes with various transform
# specifications

ax = plt.axes()
ax.set_xlim([1, 3])
ax.set_ylim([1, 3])

# Draw an ellipse over data coord (2,2) by specifying device coords.
xy_data = (2, 2)
xy_pix = ax.transData.transform_point(xy_data)

# Not providing a transform of None puts the ellipse in data coordinates .
e = mpatches.Ellipse(xy_data, width=1, height=1, fc='yellow', alpha=0.5)
ax.add_patch(e)
assert e._transform == ax.transData

# Providing a transform of None puts the ellipse in device coordinates.
e = mpatches.Ellipse(xy_pix, width=120, height=120, fc='coral',
e = mpatches.Ellipse(xy_pix, width=120, height=120, fc='coral',
transform=None, alpha=0.5)
assert e.is_transform_set() is True
ax.add_patch(e)
assert isinstance(e._transform, mtrans.IdentityTransform)

# Providing an IdentityTransform puts the ellipse in device coordinates.
e = mpatches.Ellipse(xy_pix, width=100, height=100,
e = mpatches.Ellipse(xy_pix, width=100, height=100,
transform=mtrans.IdentityTransform(), alpha=0.5)
ax.add_patch(e)
assert isinstance(e._transform, mtrans.IdentityTransform)
Expand All @@ -55,39 +55,39 @@ def test_patch_transform_of_none():
assert e.get_transform() != intermediate_transform
assert e.is_transform_set() is True
assert e._transform == ax.transData


@cleanup
def test_collection_transform_of_none():
# tests the behaviour of collections added to an Axes with various
# tests the behaviour of collections added to an Axes with various
# transform specifications

ax = plt.axes()
ax.set_xlim([1, 3])
ax.set_ylim([1, 3])

#draw an ellipse over data coord (2,2) by specifying device coords
xy_data = (2, 2)
xy_pix = ax.transData.transform_point(xy_data)
# not providing a transform of None puts the ellipse in data coordinates

# not providing a transform of None puts the ellipse in data coordinates
e = mpatches.Ellipse(xy_data, width=1, height=1)
c = mcollections.PatchCollection([e], facecolor='yellow', alpha=0.5)
ax.add_collection(c)
# the collection should be in data coordinates
# the collection should be in data coordinates
assert c.get_offset_transform() + c.get_transform() == ax.transData

# providing a transform of None puts the ellipse in device coordinates
e = mpatches.Ellipse(xy_pix, width=120, height=120)
c = mcollections.PatchCollection([e], facecolor='coral',
c = mcollections.PatchCollection([e], facecolor='coral',
alpha=0.5)
c.set_transform(None)
c.set_transform(None)
ax.add_collection(c)
assert isinstance(c.get_transform(), mtrans.IdentityTransform)

# providing an IdentityTransform puts the ellipse in device coordinates
e = mpatches.Ellipse(xy_pix, width=100, height=100)
c = mcollections.PatchCollection([e], transform=mtrans.IdentityTransform(),
c = mcollections.PatchCollection([e], transform=mtrans.IdentityTransform(),
alpha=0.5)
ax.add_collection(c)
assert isinstance(c._transOffset, mtrans.IdentityTransform)
Expand All @@ -100,7 +100,7 @@ def test_point_in_path():
path = mpath.Path(verts2, closed=True)
points = [(0.5,0.5), (1.5,0.5)]

assert np.all(path.contains_points(points) == [True, False])
assert np.all(path.contains_points(points) == [True, False])


@image_comparison(baseline_images=["clip_path_clipping"], remove_text=True)
Expand All @@ -111,6 +111,8 @@ def test_clipping():
exterior.vertices *= 4
exterior.vertices -= 2
interior = mpath.Path.unit_circle()
interior = mpath.Path(copy.deepcopy(interior.vertices),
copy.deepcopy(interior.codes[:]))
interior.vertices = interior.vertices[::-1]
clip_path = mpath.Path(vertices=np.concatenate([exterior.vertices,
interior.vertices]),
Expand All @@ -125,7 +127,7 @@ def test_clipping():
facecolor='red', alpha=0.7, hatch='*')
col.set_clip_path(clip_path, ax1.transData)
ax1.add_collection(col)

ax2 = plt.subplot(122, sharex=ax1, sharey=ax1)
patch = mpatches.PathPatch(star, lw=5, edgecolor='blue', facecolor='red',
alpha=0.7, hatch='*')
Expand Down
0