I'm trying to use the Hypertext functionality in Gnuplot (Version 5.0 patchlevel 0 last modified 2015-01-01) which is running in Cygwin/x.
The script (test_script.gp) is taken from the offical gnuplot official documentation (Hypertext section or at http://gnuplot.sourceforge.net/demo_canvas/ ):
#
# Demonstrates how to attach hypertext to points so that
# the text is displayed on mouse-over.
# Not much to see here unless you are using the wxt, svg, qt,
# or HTML5 canvas terminal.
#
set terminal canvas solid butt size 600,400 enhanced fsize 10 lw 1 fontscale 1 name "hypertext_1" jsdir "." mousing
#set output 'hypertext.1.js'
unset border
unset key
set encoding utf8
set datafile separator " "
set size ratio 1 1,1
set noxtics
set noytics
set title "Hypertext is shown when the mouse is over a point"
Scale(size) = 0.08*sqrt(sqrt(column(size)))
City(String,Size) = sprintf("%s\npop: %d", stringcolumn(String), column(Size))
GPFUN_Scale = "Scale(size) = 0.08*sqrt(sqrt(column(size)))"
GPFUN_City = "City(String,Size) = sprintf(\"%s\\npop: %d\", stringcolumn(String), column(Size))"
plot 'cities.dat' using 5:4:(City(1,3)):(Scale(3)) with labels hypertext point pt 7 ps var lc rgb "#ffee99", 'cities.dat' using 5:4:(City(1,3)):(Scale(3)) with labels hypertext point pt 6 ps var lc rgb "black" lw 0.1
pause -1 "hit return to continue"
set encoding save_encoding
reset
Calling this script fromt he cygwin/x teminal as
gnuplot -persist test_script.gp
does not produce any new window openining but returns in terminal only a sort of translation in html language.
Is there any possibility to have a new gnuplot window with the desired plot showed in it and that makes possible the mouse "hovering" functionality (hypertext) without the need of an html5 browser?
Gnuplot has file-based and interactive terminals. The canvas terminal is file-based, i.e. gnuplot generates an output file which you must view with an appropriate viewer.
If you want to view the results directly, use an interactive terminal, which do also support the hypertext option (at least the wxt, qt and windows terminals, couldn't test aqua and x11). BTW: This is also what the comment in your example file tells you!
Related
In the below code, the appearance of the curve plotted takes into account linetype and linewidth but it completely ignores linecolor.
set style line 1 linetype 1 linewidth 10 linecolor rgb "blue"
plot \
myfile using 1:2 with lines linestyle 1
I have tried to change the order of these items, as well as different ways of specifying color, eg. "#0000FF" instead of "blue".
How can I change this to have the curve take on the color specified via linestyle 1?
This is gnuplot 5.4 on Mac OS / Big Sur, tried with "Terminal" and "iterm2".
IMPORTANT UPDATE
I'm using set term postscript eps. When i change this to set term pngcairo everything is ok.
So my updated question is: How to make this work also with set term postscript eps?
Apparently, the default setting for the postscript terminal is monochrome and you have to explicitely set color. I remember having seen similar questions in the past. I don't know why default is monochrome, maybe historical reasons? So, it seems to be a recurring "pitfall", since users nowadays think everything is in color per default ;-).
set term postscript eps color
That's what I get (on a "fresh" console) if I type set term postscript eps. Apparently, text is in color per default (i.e. labels and arrows), but the rest seems to be monochrome.
Options are 'eps enhanced defaultplex \
leveldefault monochrome colortext \
dashlength 1.0 linewidth 1.0 pointscale 1.0 butt noclip \
nobackground \
palfuncparam 2000,0.003 \
"Helvetica" 14 fontscale 1.0 '
set term epslatex
...and it works! (since i wanted "eps", and got "eps").
Incidentially (although it produces "png" instead of "eps") set term pngcairo and possible many more "term"s also work.
Strange thing is that I didn't get any warning when plotting with set term postscript eps that gnuplot was not able to apply the linestyle coloring with that terminal mode.
I know the epslatex terminal can be used to have fonts in latex style.
But how can I emulate math latex fonts in the postscript terminal?
set term postscript size 5,4
set out "test.ps"
pl [][-1.1:1.1] sin(x) t "sin {/Italics x}"
set out
In math latex
it would look like:
So it seems I want a serif font.
IMHO this is far more trouble than it is worth. But if you really want to you can download Adobe Type 1 versions of the standard TeX fonts for use in PostScript, specifically for use by the gnuplot postscript terminal. Here is a demo.
#
# Demonstrate use of TeX Computer Modern fonts in gnuplot PostScript terminal
# This demo requires Adobe Type 1 fonts that may not be installed on your system.
# If necessary you can download them from
# http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/pfb/cmr10.pfb
# http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/pfb/cmmi10.pfb
# http://mirrors.ctan.org/fonts/cm/ps-type1/bakoma/patched-pfb/cmsy10.pfb
#
set term post eps color fontfile 'cmr10.pfb' fontfile 'cmmi10.pfb' fontfile 'cmsy10.pfb'
set output 'cmfonts.eps'
set title "Use of TeX Computer Modern fonts in gnuplot PostScript terminal"
set label 1 'Times-Roman: {/Times-Roman abcdefghABCDEFGH}'
set label 2 'cmr10: {/cmr10 abcdefghABCDEFGH}'
set label 3 'cmmi10: {/cmmi10 abcdefghABCDEFGH} {/cmmi10 \013\014\015\016\042}'
set label 4 'cmsy10: {/cmmi10 abcdefghABCDEFGH} {/cmsy10 \013\014\015\016\042}'
set label 1 at graph 0.05,0.6 left
set label 2 at graph 0.05,0.5 left
set label 3 at graph 0.05,0.4 left
set label 4 at graph 0.05,0.3 left
set xlabel "{/cmmi10 \013}"
plot [0:2*pi] sin(x) title "{/cmr10 sin({/cmmi10 \013})}"
Serif (Times) in combination with Oblique (Italic) also emulates a bit the look of latex math.
set term postscript size 5,4
set out "test.ps"
set label 1 'Serif: {/Serif abcdefghABCDEFGH}' at graph 0.05,0.5 left
set label 2 'Serif Oblique: {/SerifOblique abcdefghABCDEFGH}' at graph 0.05,0.4 left
set label 3 'Symbol: {/Symbol abcdefgh}' at graph 0.05,0.3 left
set label 4 'Symbol-Oblique: {/Symbol-Oblique abcdefgh}' at graph 0.05,0.2 left
pl [0:2*pi] sin(x) t "{/Serif sin} {/SerifItalics x}"
set out
This does not fully look as I asked for, but may look even better in documents using Times anyway.
The credit for Oblique goes to http://www.gnuplotting.org/postscript-terminal-with-italic-symbols/.
After noticing the interactive gnuplot graphic upon https://lwn.net/Articles/723818/ showing country names on a mouse hover, I am wondering how to simply show the values of the points in a plot.
For example I want to hover over the "daughter bar" in https://s.natalian.org/2020-08-24/mouse-hover.svg and see 60 clearly.
However right now it just shows co-ordinates IIUC. How do I fix this?
set term svg mouse standalone
reset
$heights << EOD
dad 181
mom 170
son 100
daughter 60
EOD
unset key
set boxwidth 0.5
set style fill solid
set yrange [0:*]
plot '$heights' using 2:xtic(1) with boxes
set output '/tmp/mouse-hover.svg'
replot
You are looking for hypertext, check help hypertext.
You have to use point to anchor the hypertext.
Play with the pointsize (here ps 3) to change the area where the mouse will display the hypertext.
Since you probably don't want to display a colored point at the top of your box, make the color transparent, e.g. lc rgb 0xff123456.
Unfortunately, I haven't found (yet) anything in the gnuplot documentation how to make the font of this hypertext larger. The option font ",30" does not have any effect. If you find out please let me know. Apparently in wxt terminal you can do it (see gnuplot: Hypertext with monospace?).
Code:
### SVG standalone with hypertext
reset session
set term svg mouse standalone enhanced
set output 'tbSVGstandalone.svg'
$heights <<EOD
dad 181
mom 170
son 100
daughter 60
EOD
unset key
set boxwidth 0.5
set style fill solid
set yrange [0:*]
plot '$heights' u 2:xtic(1) w boxes,\
'' u 0:2:2 w labels hypertext point pt 7 ps 3 lc rgb 0xff123456
set output
### end of code
Result: (screenshot of SVG in Firefox. It looks like I can't place a SVG here, at least I don't know how.)
I often use the wxt terminal of Gnuplot to do some quick data inspection. I like the interactivity, such that I can easily gain control and zoom/move et cetera.
Suppose I have to following script
set terminal wxt 0 persist
plot x
set terminal wxt 1 persist
plot x**2
Now, on window 1 I have the interactive control. However, on window 0 this interactive control is lost.
My question is: How can I obtain interactive control on window 0?
I am using gnuplot 4.6.2. I've seen gnuplot multiple graphs are not interactive but the question in about x11 terminal, and the answers consist of opening multiple instance of gnuplot, which seems unnecessary to me.
I believe have found a workaround for this problem.
But not sure if this works for all cases.
My solution sounds like obvious.
I created three files: configs.plt, wxt1.plt, and wxt2.plt.
The configs.plt file contains:
set style line 1 lc "#e41a1c"
set style line 2 lc "#377eb8"
The wxt1.plt file contains:
set terminal wxt title "plot sin"
load "configs.plt"
plot sin(x) w l ls 1
The wxt2.plt file contains:
set terminal wxt title "plot cos"
load "configs.plt"
plot cos(x) w l ls 2
The only boring thing is run two instead one file.
UPDATE: this issue has been resolved in newer versions (>5.0) of gnuplot; see #andyras' answer.
I am having difficulty getting gnuplot to create labels with bold and enhanced text in non-postscript terminals. The following script
#!/usr/bin/env gnuplot
reset
set terminal pdfcairo enhanced color lw 3 size 3,2 font 'Arial-Bold'
set output 'output.pdf'
set tics scale 0
plot -x title 'normal text', \
-2*x t 'enhanced_{text}', \
-3*x t '{/Arial-Bold attempt to specify_{font}}'
set terminal pngcairo enhanced color lw 3 size 400,300 font 'Arial-Bold'
set output 'output.png'
replot
set terminal postscript enhanced color lw 3 size 6,4 font 'Arial-Bold'
set output 'output.eps'
replot
reset
Produces the following eps (converted to png with convert output.eps -rotate 90 outputeps.png):
which is fine. However, when I use the pdf or png terminals the result looks like this:
Note that while all the label text should be bold, only the label without any enhanced text is bold. In addition, when I try to manually specify the font (last line title) the font is different (reverts to the default?).
Is this behavior I should expect when not using the postscript terminal? Is there another way to specify fonts (i.e. is the naming scheme different outside of postscript)?
Since version 5.0, gnuplot has a new syntax to handle this issue:
"normal text {/Times:Bold boldface-newfont} {/:Italic slanted-default-font } back to normal text"]
These brackets can also be nested.
For Better results in pdf format.
Plot the curves using enhanced eps terminal. Then use Imagemagic to convert your output to pdf format. using the commands
convert myPlot.eps myPlot.pdf
Default resolution with this commands generates a poor output. This can be overcome by using density option with a value of 300. Modified command looks like
convert -density 300 myPlot.eps myPlot.pdf
I found that this preserves all the text formatting of eps file in pdf file.