yury10578
yury10578

Reputation: 113

Is it possible in Gnuplot to have resolution independent element sizes?

So, is it possible to make Gnuplot output e.g. lines 1 point thick or 24 points-sized characters in labels, regardless of what plot size and rendering device resolution I use?

Right now it seems to me Gnuplot won't do that 'out of the box'. Everything's measured in pixels, right, even if rendering to Postscript terminals?

I'm working on a set of plot images, for which not all final (rendering) metric sizes are known in advance. After scaling to different geometries, line widths look perceptibly different and untidy. Same with symbols and glyphs.

Also, it's too hard to predict what the plot would look like when previewing it in a raster gnuplot terminal and a Postscript one.

I guess it's possible to insert some code in plots to auto-calculate pixel sizes from plot size and desired element size, which would sort of work, but is that an only option?

Upvotes: 0

Views: 70

Answers (2)

yury10578
yury10578

Reputation: 113

I don't have much time at the moment to be more elaborate, so I'll put here an intermediate half-answer to my own question, for the benefit of people with the same issue.

The gist is: it is possible, but in a very inprecise manner. You are better off with raster-based pngcairo terminal, with some additional self-imposed use constraints.

Here go two small files I've used, the first is to be fed directly into gnuplot (the 90 value is my screen dpi, as I haven't been able to set up a test environment with a printer, and ended testing everything on-screen):

not72 = 72.0/90.0 ;
_1mm = 72.0/25.4 ; _1pt = 25.4/72.0 ;

set output ARG0 . '_pngcairo.png'
set term pngcairo \
  enhanced font "NimbusRoman,24" size 5*90,5*90 \
  linewidth 1.0 dashlength 1.0 pointscale 1.0 fontscale 1.0 

load "drawing.gp"

set output ARG0 . '_pngcairo_scaled.png'
set term pngcairo \
  enhanced font "NimbusRoman,24" size 5*90,5*90 \
  linewidth 1.0/not72 dashlength 1.0/not72 pointscale 1.0/not72 fontscale 1.0/not72 
replot

set output ARG0 . '_pdfcairo.pdf'
set term pdfcairo \
  enhanced font "Nimbus Roman,24" size 5in,5in \
  linewidth 1.0 dashlength 1.0 pointscale 1.0 fontscale 1.0 
replot

set output ARG0 . '_epscairo.ps'
set term epscairo \
  enhanced font "Nimbus Roman,24" size 5in,5in \
  linewidth 1.0 dashlength 1.0 pointscale 1.0 fontscale 1.0 
replot

The drawing.gp file follows:

unset key
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0

set label "1in\nLF" at 0,5 font ",72"

function $dimline(x1,y1,x2,y2) << EOF
  set arrow from first x1,y1 to x2,y2 lw _1mm
  set arrow from first x2,y2 to x1,y1 lw _1mm
EOF

tmp = $dimline( 4.5,0, 4.5,9.9)
set label "5in long" at 5.15,2 rotate by 90

tmp = $dimline( 0,6, 9.9,6)
set label "1mm thick" at 2,6.35

plot [0:10][0:10] \
  8 with lines ls 1 lw _1mm*50 \
  , 2 with points pt 12 ps 10

Superficial browsing of Gnuplot sources showed there's a lot of ad-hoc stuff there relating to sizes and scaling. I can't dig into all this at the moment.

So, to recapitulate, to use scalable sizes, you should do all the scaling by yourself employing a raster-type terminal, e.g. pngcairo.

The Gnuplot version used was Version 6.0 patchlevel 0 last modified 2023-12-09.

Upvotes: 0

Ethan
Ethan

Reputation: 15118

Your premise is incorrect. Some output modes (terminals) are pixel-based; others are not. Gnuplot passes both line widths and font sizes to PostScript in 'point' units. If the output is to be scaled up to a greatly different size, say for a poster, then you may want to scale the graphical elements and text correspondingly using the optional terminal keywords.

For example, suppose you first prepare and preview a figure on a standard letter-size paper. The default PostScript output in landscape mode is 10 inches by 7 inches

set term postscript landscape font "Times,12"
set output 'draft.ps'
load "my_complicated_plot.gp"

Now you want to blow this up to poster size, but you want the graphical elements and text to scale up proportionally. Rather than changing any of the commands that belong to the plot description, you modify the terminal setting:

set term postscript landscape font "Times,12" size 20in, 14in \
       linewidth 2.0 pointscale 2.0 fontscale 2.0 
set output 'bigger.ps'
load "my_complicated_plot.gp"

The bigger.ps output file would use a true font size of 24pt Times; lines originally drawn by, say, plot foo with lines linewidth 3 would have a true final thickness of 6pt.

Upvotes: 0

Related Questions