FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Gray lines in empty figure · Issue #117 · matplotlib/matplotlib · GitHub

Repository navigation

Gray lines in empty figure #117

Closed
Closed

Description

The following simple script:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(6, 6))
fig.savefig('line.png', dpi=40)

Produces a file that has a faint gray line one pixel wide on the left and top edges. What could be causing this, and is there a way to turn those lines off? I've uploaded the output file here

Activity

  1. WeatherGod commented on May 17, 2011

    Member

    The line isn't actually there. Using 'eog', it appears to me as a dashed gray line. And then, using another viewer that did not fully support PNG transparency, there was no line at all. In Gimp, I didn't see a line either. If anything, either we have an off-by-one error in saving our files, or your display software and 'eog' has an off-by-one error.

  2. astrofrog commented on May 17, 2011

    ContributorAuthor

    It must be something to do with the alpha channel. I see the 'line' in Preview.app, and also if I convert to a different format using imagemagick:

    convert line.png line.tif
    
  3. astrofrog commented on May 17, 2011

    ContributorAuthor

    Gimp shows the left and top pixel as being transparent, and by going to Colors -> Components -> Decompose -> Alpha you can see that the alpha channel will produce semi transparent left and top borders.

  4. added a commit that references this issue on May 17, 2011
    e7f1e83
  5. mdboom commented on May 17, 2011

    Member

    This is due to pixel-snapping. To get sharp lines, vertices are rounded to the nearest pixel. In the case of odd (i.e. non-even) stroke widths, the vertices are then shifted half a pixel down and to the right so their centers are on the center of the pixel.

    The bug here is that the figure patch (the background of the figure) has a stroke width of 1.0, even through it was an edgecolor of None (i.e. it isn't actually drawn). So the entire rectangle gets shifted half a pixel down and to the right.

    There are a number of ways to fix this, and I think we should probably do all of them to cover all bases, even though any one of them is sufficient for the problem at hand.

    1. Set the default stroke width of the figure patch to 0.0
    2. Change the snapping algorithm so there is no half-pixel adjustment when there is a stroke width but no stroke color
    3. Draw the figure patch with anti-aliasing turned off, since it's always a solid rectangle (has the advantage of being faster, too)

    A solution is on my figure_edge branch.

  6. astrofrog commented on May 17, 2011

    ContributorAuthor

    @mdboom - that patch fixes the issue for me

    I have another issue with similar symptoms which is not fixed by the patch, so I've opened a new issue (#118)

  7. added a commit that references this issue on Jun 2, 2011
    cd28725
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL