From: Ethan A M. <me...@uw...> - 2021-02-05 04:06:42
|
On Thursday, 4 February 2021 16:39:13 PST m sutton wrote: > I was checking out v5.4.1 on centos 7.2 with gdlib 2.3.0. I > simplified the problem down to this script. > > unset grid > set nokey > set clip two > > set title "GD Line Bug" > set size 1,1 > set term png small truecolor butt size 500,400 > unset border > unset tics > set output 'mike.png' > set xr [0:6]; > > set yr [0:2] > > plot '-' u 1:2 notitle w l lt 1 lw 9 > 2.0 1.0 > 5.0 1.0 > e > > > I get a small, but noticeable dash at the beginning of the > plotted line. The larger the linewidth the more noticeable it > becomes. I have not looked at the libgd internals for a long time. I remember that back in the day (2004-ish) the libgd support for linewidth greater than 1.0 was really bad. To work around this, gnuplot does not use gdImageSetThickness() to draw thick lines; instead it defines a brush with a finite square or circular nib and draws using brush strokes. This approach is acceptable for lines with end property "square" or "round", but is not compatible with line end property "butt". So when the option for "set term png butt" was added, the corresponding code went back to using the built-in gdlib gdImageSetThickness(). And it is apparently still really bad. The relevant changes to the gnuplot source code appear to be: %%%%%% commit e69e5d055ac94a949e8cfcce87f0bebfbee301cf Author: Mike Sutton <mw...@us...> Date: Thu Jan 6 21:34:33 2005 -0800 New terminal option {rounded|butt} %%%%% %%%%% commit 9a83ae5a4d653f179554045876d37a482f745a74 Author: Mike Sutton <mw...@us...> Date: Sat Nov 25 14:09:53 2006 -0800 Fix off-by-one error in specifying line widths %%%%% So I refer you to the author of the code 😉 😉 😉 I seriously suggest to bail on using gdlib and instead use "set term pngcairo". > I inserted a print statement in the PNG_vector function in > gd.trm. What I see are two calls to PNG_vector. The first call > tries to plot a line of zero length. The second call plots the > correct line. > > > So why is the zero length line plotted? You can see this in the generic code for plot_lines (graphics.c:1257). There is a grand loop over all points in the data set. Each one generates a new line segment if either end is INRANGE. The very first point thus generates a zero-lenght line segment. It's been that way since forever. My guess is that the original idea was that any INRANGE point should be visible in the plot, even if the points on either side were undefined or out of range. cheers, Ethan |