Skip to content

Hatching gap on agg backend #853

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 1 commit into from
Apr 27, 2012
Merged

Hatching gap on agg backend #853

merged 1 commit into from
Apr 27, 2012

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Apr 25, 2012

Every 72 pixels, with some hatch patterns, the hatch line is interrupted in the agg backend.

ax = plt.axes()
patch = mpatches.Rectangle([0, 0], 1, 1, transform=ax.transAxes, hatch='/', facecolor='none')
ax.add_patch(patch)

# put boxes where there are gaps (in device pixel coordinates)
fig = plt.gcf()
w, h = fig.transFigure.transform([1, 1])

box_height = 11 
box1_x, box1_y = 144 - box_height/2, h - 145 + box_height/2

for i in xrange(3):
    for j in xrange(3):
        patch = mpatches.Rectangle([box1_x + i*72, box1_y - j*72], box_height, box_height, transform=None, facecolor='none')
        fig.patches.append(patch)

plt.show()

An interesting observation is that when using the hatch "x" the artefact doesn't exist, which suggests there may be an anti-aliasing influence at the edge of the tile before it is passed through as an agg::span_pattern_rgba.

I have tried changing the agg renderer in src/_backend_agg.cpp to renderer_bin for hatch pattern rendering, in the hope that it would be a simple anti-aliasing problem, but the problem persists. Unfortunately that is as far as I have been able to take it.

@mdboom
Copy link
Member

mdboom commented Apr 25, 2012

The attached PR should resolve this (I think). The corners of the hash pattern were not getting inked. Using parallel lines of the same length, rather than lines that shrink to zero length in the corners, seems to fix this problem. Agg draws a zero length line as nothing, whereas other renderers (Adobe Acrobat, for example) draw a zero length line as a point.

There is also a bug whereby the density of diagonal lines was much higher than horizontal or vertical ones so the spacing should be less crowded now. They can't be made to be the same, because the pattern is a fixed size regardless of line direction, so if the spacing of horizontal lines is 'x', the spacing of diagonal lines is \sqrt{2x^2}.

@@ -43,37 +43,28 @@ def set_vertices_and_codes(self, vertices, codes):
class NorthEastHatch(HatchPatternBase):
def __init__(self, hatch, density):
self.num_lines = (hatch.count('/') + hatch.count('x') + hatch.count('X')) * density
self.num_vertices = self.num_lines * 4
self.num_vertices = (self.num_lines + 1) * 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good when num_lines == 0 as we end up with a single point in the hatch pattern. 7242fd67921fff5c7651692e097cfdb7dde174ab, in my own branch from yours, fixes this and adds a fix to the anti-aliasing effect on horizontal and vertical hatches.

@pelson
Copy link
Member Author

pelson commented Apr 26, 2012

Awesome response time Mike. It took me ages to look into this without success! (I guess my initial guess that it was an aa effect is to blame for that)

mdboom added a commit that referenced this pull request Apr 27, 2012
Hatching gap on agg backend
@mdboom mdboom merged commit 3d19a08 into matplotlib:master Apr 27, 2012
@mdboom mdboom deleted the hash_gaps branch March 3, 2015 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants