2

What is the reason that lw 0 doesn't have zero linewidth, i.e. invisible?

What I find in the gnuplot manual:

The line width and point size are multipliers for the current terminal's default width ...

Ok, if lw 0 is a multiplier then the resulting linewidth should be zero independent of the terminal's default linewidth.

The reason for asking is to eventually have the possibility to use with linespoints and programmatically switch within a loop between with lines and with points.

Code:

### linewidth 0 isn't zero
reset session

set key out
set yrange[-0.9:10.9]
set ytics 1

plot for [i=0:10] i with lines lw i title sprintf("linewidth %g",i)

### end of code

Result:

enter image description here

By the way, what are the artefacts at the y-axis e.g. at ytics 3,4,6,7,9,10 (wxt-terminal)?

theozh
  • 22,244
  • 5
  • 28
  • 72
  • The artefacts probably have something to do with line end-caps. But they don't look consistent, so that's really weird. – Mike Nakis May 08 '20 at 18:01
  • @Mike Nakis, right, that's something with the terminal library. On wxt-terminal, you have 3 options for line end-caps, `butt`, `square` and `rounded`. With the first two you will get strange artifacts, `rounded` seems to be fine. windows-terminal with 2 options `butt` and `rounded` are both fine. qt-terminal does not have options, but seems to have no artifacts. – theozh May 09 '20 at 11:37

2 Answers2

3

I don't know for sure what the official explanation is for gnuplot in particular, but in my experience, most graphics packages / tools / libraries etc. use a special convention for a line width of zero.

According to this convention, a line width of zero does not mean invisible; it simply means "the thinnest line possible". This means the thinnest line that can be displayed on the device, regardless of zoom, transformations, logical-to-physical mapping, etc.

So, on monitors, it will be a line which is one pixel wide.

On a printer, it will be the thinnest line that the printer is capable of producing. So, if the printer has a high enough resolution, then the line might practically be invisible, though a magnifying glass should still be able to reveal its existence.

And note that "regardless of zoom, etc." means that even if you set up some scaling that makes your 10-point line look as thick as 100 pixels, the zero-width line will still be exactly one pixel thick.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
3

Mike Nakis is correct that for at least some of the gnuplot output terminals, including PostScript, gnuplot asks for a 0 width line and the language or library in question interprets that as "1 pixel" or "thinnest possible line".

Similarly "pointtype 0" is not truly missing, it produces a single pixel dot.

You can, however, disable the line drawing altogether by using linetype "nodraw". That gives a complementary pair of commands

plot sin(x) with linespoints lt nodraw pt 7         # only the points are visible
plot sin(x) with linespoints lt 1 pt 0              # only the lines are visible

In some circumstances it may help to know that the numeric equivalent for lt nodraw is lt -2.

Ethan
  • 13,715
  • 2
  • 12
  • 21
  • Thank you! that's exactly what I was looking for. Looks like an undocumented feature, I couldn't find `nodraw` in the 5.2.8 PDF manual. – theozh May 09 '20 at 05:04
  • by the way, can you also explain the artifacts at the y-axis? Maybe when do they appear and how to avoid? – theozh May 09 '20 at 05:06
  • ok, good to know: for `w lp lt nodraw` I get the default points (crosses) whereas for `w lp lt -2` I get nothing, except I **explicitely** specify the pointtype **and** the linecolor, i.e. `w lp lt -2 pt 1 lc 1`. – theozh May 09 '20 at 05:43
  • Each linetype has an assigned color, width, pointtype, dash pattern, etc. When you say `plot ... lt N` this pulls in the associated properties including point type. You can override this by giving an explicit point type. The pointtype and linecolor associated with lt nodraw are useless so yeah, if you use `linetype nodraw` but still want points and a color then you'll have to add those properties back to the plot command. For normal linetypes you could also change the associated point type etc using the `set linetype` command, but that won't work for special linetypes like `nodraw`. – Ethan May 09 '20 at 06:30