Re: Problem/bug with ends of thick lines in graphics
- To: mathgroup at smc.vnet.net
- Subject: [mg88397] Re: Problem/bug with ends of thick lines in graphics
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Mon, 5 May 2008 06:07:24 -0400 (EDT)
- Organization: University of Bergen
- References: <fvhe27$3t8$1@smc.vnet.net>
David Reiss wrote:
> In a quick search of things I haven't found a mention of the following
> simple graphics issue and I'm checking in with the group to see if
> there is a memory of its mention and if there is a simple fix (and
> which is not a complicated hack) that I've not been able to come up
> with.
>
> Consider the following graph:
>
> Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}},
> PlotStyle -> {AbsoluteThickness[20]}]
>
> When you plot it you will see that the line's ends are not
> rectangular, whereas you would certainly want them to be so. (An
> alternative would be to have them be rounded, for example, but the
> question will remain the same whatever your preference is.) Rather
> they appear as polygonal in a way inconsistent with the line itself.
>
> One assums that this is an artifact of how the line is rendered based
> on the individual line segments, and that that segmental rendering has
> to do something with how a segment relates to the segments on either
> side of it. The lack of a segment beyond the end segment presumably
> runes the algorithm for rendering in a way that leads to this
> appearance.
>
> I have two related questions here. The first is how, if at all
> possible, to fix this in a general way through some specific options
> settings for the graphics function.
>
> The second is how, when exporting this graphic as, say, a PDF, to make
> it behave properly.
>
> There was a trick in pre version-6 Mathematica that would involve
> adding an explicit postscript command to the PlotStyle option. Though
> this would not (I think) correct the screen appearance of the graphic,
> it would properly fix it when the graphic was exported to PDF or EPS.
> Here is an example of how it was done:
>
> Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}},
> PlotStyle -> {{ PostScript["0 setlinecap"],AbsoluteThickness[20]}}]
>
> This, however, no longer works in Mathematica 6+ presumably because of
> the new way that graphics rendering is handled.
>
> Does anyone have any solutions to either or both of these issues?
>
I brought this up two or three times on MathGroup, but never received a
reply ... So I guess that we have to live without this feature in
Mathematica 6 ...
I used to use PostScript[" ... "] in Mathematica <= 5.2 to set line caps
and line joins. The default was round cap and round join. But
PostScript[] does not work any more---not even with EPS or MPS output.
(One cannot expect it to work with other outputs, of course.)
Unfortunately they changed the defaults to square cap and miter join in
Mathematica 6. I think that this was the worst possible choice ... The
square caps/joins take up more space than either of the two other
possibilities (bevel/round join), so it is not even possible to emulate
these by adding bullets at line joins ...
Miter joins cause heavily fluctuating ListPlots to look very ugly and
"pointy", like a hedgehog. They could look much better with round joins.
Here's an example:
ListPlot[{{0, 0}, {1, 5}, {2, 0}}, Joined -> True,
PlotStyle -> Thickness[.1], PlotRange -> {{-1, 3}, {-1, 6.5}}]
Imagine this repeated a thousand times with sharper angles.
http://www.capcode.de/help/setlinejoin
http://www.capcode.de/help/setlinecap
Unfortunately the pointy line joins are not the only things that can
cause troubles ... The shape of a Point[] can also be quite strange at
small sizes: Mathematica switches to square or other point shapes at
small sizes, which is useful for raster graphics, but does not make any
sense for PostScript/PDF output. And the PostScript output generated
for Point[]s is just awful: instead of defining one simple point drawing
command, and using it consistently, these whole series of commands for
drawing these strange shapes is repeated for each point. Just try the
following to see what I mean:
ExportString[Point[RandomReal[1, {10, 2}]] // Graphics, "EPS"]
Yet another graphics export problem is this:
ap = ArrayPlot[RandomInteger[1, {200, 200}],
ColorFunction -> (If[# > 0.5, Black, White] &)];
gr = GraphicsRow[{ap, ap}]
Export["gr.pdf", gr]
Open the PDF and see how the small black and white squares that make up
the graphic are completely misaligned, making the output completely
useless. The PDF output looks completely different than the rendering
in the front end.
I really hope that these problems will be fixed for 6.1 ...