Overlap with bar

Hi, When plotting a large amount of bars, like

    >>>> bar(arange(500), rand(500))

    > the bars seem to overlap and it produces a weird effect.

    > My feeling is that the culprit is the contour line around
    > each rectangle, who probably don't scale properly in this
    > limit. In fact, the problem is maybe not so much that the
    > contour width doesn't scale, but that the contour is drawn
    > outside the rectangle.

    > I'd be glad to submit a patch, but I'd need some directions
    > (where in the code is the contour drawn ?)

This is likely due to either antialising of the bar patch.Rectangle
objects (does it help to turn the antialiased property off?) or
subpixel rendering (does it help to comment out these lines in
src/_backend_agg.cpp in the draw_polygon function?)

    //snapto pixel centers
    x = (int)x + 0.5;
    y = (int)y + 0.5;

JDH

John, David,

The problem is indeed the patch boundaries; here is the workaround:

In [2]:bb = bar(arange(500), rand(500))

In [3]:for b in bb: b.set_linewidth(0)
    ...:

In [4]:draw()

We should probably do something like setting linewidth to zero automatically if edgecolor is None, so that the existing edgecolor kwarg can be used to achieve this result. And/or add a linewidth kwarg.

Eric

John Hunter wrote:

···

    > Hi, When plotting a large amount of bars, like

    >>>> bar(arange(500), rand(500))

    > the bars seem to overlap and it produces a weird effect.

    > My feeling is that the culprit is the contour line around
    > each rectangle, who probably don't scale properly in this
    > limit. In fact, the problem is maybe not so much that the
    > contour width doesn't scale, but that the contour is drawn
    > outside the rectangle.

    > I'd be glad to submit a patch, but I'd need some directions
    > (where in the code is the contour drawn ?)

This is likely due to either antialising of the bar patch.Rectangle
objects (does it help to turn the antialiased property off?) or
subpixel rendering (does it help to comment out these lines in
src/_backend_agg.cpp in the draw_polygon function?)

    //snapto pixel centers
    x = (int)x + 0.5;
    y = (int)y + 0.5;

JDH

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Thanks a lot for the quick answer,

I think it would be cleaner to add the linewidth argument, since most users expect the default to be a black boundary.

FWIW, here is a patch (untested, I’m at home and I don’t dare compile Matplotlib on windows).

I’ll test it somewhere next week.

David

2006/12/7, Eric Firing <efiring@…229…>:

bar_linewidth.patch (1.82 KB)

···

John, David,

The problem is indeed the patch boundaries; here is the workaround:

In [2]:bb = bar(arange(500), rand(500))

In [3]:for b in bb: b.set_linewidth(0)
…:

In [4]:draw()

We should probably do something like setting linewidth to zero
automatically if edgecolor is None, so that the existing edgecolor kwarg
can be used to achieve this result. And/or add a linewidth kwarg.

Eric

John Hunter wrote:

> Hi, When plotting a large amount of bars, like
>>>> bar(arange(500), rand(500))

> the bars seem to overlap and it produces a weird effect.

> My feeling is that the culprit is the contour line around
> each rectangle, who probably don't scale properly in this
> limit. In fact, the problem is maybe not so much that the
> contour width doesn't scale, but that the contour is drawn
> outside the rectangle.

> I'd be glad to submit a patch, but I'd need some directions
> (where in the code is the contour drawn ?)

This is likely due to either antialising of the bar patch.Rectangle
objects (does it help to turn the antialiased property off?) or
subpixel rendering (does it help to comment out these lines in
src/_backend_agg.cpp in the draw_polygon function?)

//snapto pixel centers
x = (int)x + 0.5;
y = (int)y + 0.5;

JDH


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash

http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

David,

I went ahead and added the linewidth kwarg to bar and barh in svn, and did a little bit of other cleaning up at the same time.

Eric

David Huard wrote:

···

Thanks a lot for the quick answer,

I think it would be cleaner to add the linewidth argument, since most users expect the default to be a black boundary.