Why is output.eps 0kb? - gnuplot

I have code:
set term eps size 1200,150
set output "output.eps"
set tics out
set xlabel "{/:Italic A} (B)"
set ylabel " "
set ytics nomirror
set xtics nomirror
unset ytics
unset key
#set key tc variable
set label "{/:Bold=12 S}" tc rgb "black" at 54250,5.05
set label "{/:Bold=12 F}" tc rgb "black" at 56170,5.05
set label "{/:Bold=12 R}" tc rgb "black" at 56730,5.05
set arrow from 56000,graph(0,0) to 56000,graph(1,1) nohead dt "-" lw 1 lc rgb "grey30"
set arrow from 56500,graph(0,0) to 56500,graph(1,1) nohead dt "-" lw 1 lc rgb "grey30"
plot 'data.txt' title "{/:Bold T data}" with points pt 7 ps 1 linecolor rgb "black",
and the output.eps has 0kb. What is wrong please? output.png is ok with this code.
Edit
.png - desired
.eps

For some terminals the output file is written when the output is "closed". This can be done by:
calling the command set output after the plot command, you have to call another set output <filename> when you want another plot
closing gnuplot, this works automatically if you write your commands into a scriptfile (for example script.plt) and load your gnuplot script from the shell commandline with gnuplot script.plt

Related

Set color to grey for points below some cutoff when plotting with palette in Gnuplot

Sorry for the long and probably poor title.
I am trying to plot some data in gnuplot, where the data file has the format
x y z
1.0 1.5 0.1
1.3 1.8 0.7
2.1 3.7 1.1
3.1 4.3 1.5
3.7 4.7 1.8
I want to plot y vs. x and, for each point, indicate the value of z by the color of the point. Currently I use the following code for this:
size = 0.5
type = 7
set term pngcairo
set output 'Foo.png'
set palette rgbformulae 22,13,-31
set cblabel "z"
unset key
set xlabel 'x'
set ylabel 'y'
set title 'y vs. x'
plot "Data.txt" u 1:2:3 w p pt type ps size palette
This works, but I would like to make the following change: For each point whose z value is below a cutoff, say 1.0, I want the color to be set to grey, regardless of the z-value. Then for z-values greater than or equal to the cutoff, I want the color to be picked from the palette according to the z-value.
Thus, I want the color to go discontinuously from grey to blue (for the current palette) at the cutoff value. Can this be done, and if so how?
It is difficult to do with a palette based on rgbformulae. It's relatively easy with a defined palette. Here is an example that gives a palette close to what you chose, with a dark gray tacked on at the bottom end. cbrange is then set so that your z cutoff is the minimum. All z values below cbmin will be assigned the endpoint value, which is dark gray in this case.
set xrange [0:1]; set yrange [0:pi]
set sample 100; set isosample 100
set palette defined (-0.01 "grey20", 0 "blue", 0.4 "green", 0.6 "yellow", 1.0 "red")
zmin = -0.6
set cbrange [zmin: *]
set xyplane at zmin
splot cos(x)*sin(y+y*(x*x)) with pm3d
After gnuplot 5.4, this can be achieved by using the function "palette()" in "using" and combining it with the "with point lc rgb variable".
size = 3 ### 0.5 in original code
type = 7
set term pngcairo
set output 'Foo.png'
set palette rgbformulae 22,13,-31
set cblabel "z"
unset key
set xlabel 'x'
set ylabel 'y'
set title 'y vs. x'
set cbrange [0:2] ### this is required by palette() function
gray = 0x808080 ### gray color expressed by integer
plot NaN w p palette, \
"Data.txt" u 1:2:($3<1 ? gray : palette($3)) w p pt type ps size lc rgb variable
The RGB value passed to "lc rgb variable" are determined by comparing $3 with threshold value 1(for example).
"NaN w p palette" is a dummy plot, a technique for forcing the colorbox to appear. Without it, the colorbox will not be displayed.
Here is a gnuplot 5.2 version. You can use a rgbformulae palette.
It uses the datablock $PALETTE which is created after carrying out the command test palette.
Code: (tested with gnuplot as low as 5.2.0)
### cut-off colors for a given rgbformulae palette (gnuplot >=5.2)
reset session
# create some test data
set xrange [-5:5]
set yrange [-5:5]
set samples 50
set isosamples 50
set table $Data
splot (sin(1.3*x)*cos(.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x))*3
unset table
set palette rgbformulae 22,13,-31
test palette # necessary to put the palette into the datablock $PALETTE
myColorMin = 0
myColorMax = 6
myOutOfRangeColor = 0x808080
myColorPos(c) = int(255.0 * (c-myColorMin)/(myColorMax - myColorMin))+1
myColor(c) = c<myColorMin || c>myColorMax ? myOutOfRangeColor : \
(int(word($PALETTE[myColorPos(c)],2)*0xff)<<16) + \
(int(word($PALETTE[myColorPos(c)],3)*0xff)<<8) + \
(int(word($PALETTE[myColorPos(c)],4)*0xff))
set cbrange [myColorMin:myColorMax]
set view 36, 72
set ztics 5
splot $Data u 1:2:3:(myColor($3)) w pm3d lc rgb variable notitle
### end of code
Result:

No mxtics in logscale with gnuplot

I am having troubles making Gnuplot show the intemediate tics (mxtics) in a log scale. I have looked up similar topics, but none of the answers work for me. Please find enclosed a minimal working example,
set size 1,1
set origin 0,0
unset xtics
set yrange [-1:1]
set xrange [1e-6:2]
set mxtics 10
set logscale x
set format x ""
set xtics 1, 1e-2
set xtics 1e-4, 1e-6
set xtics add ("10^{-4}" 1e-4,"10^{-2}" 1e-2, "1" 1) offset 0,0
set xtics nomirror
set format y ""
unset ytics
p 0.0
which provides the following output, with no mxtics:
I would like to have 10 mxtics per decade, i.e., one at 10^{-2}, one at 2 10^{-2}, ..., one at 9 10^{-2}. Do you know how to do that? I have tried changing the order of the command lines, but it didn't work.
FYI, here is the Gnuplot version that I am using:
$ gnuplot
G N U P L O T
Version 5.2 patchlevel 2 last modified 2017-11-15
EDIT: The following is tentative way to make this work:
set xrange [1e-6:1]
set yrange [-1:1]
set logscale x
set format x "10^{%T}"
set xtics add ("" 1e-3, "" 1e-5, "" 1e-1)
set mxtics 10
set xtics nomirror
set format y ""
unset ytics
unset ylabel
p 0 w l lw 2 linecolor rgb "black" noti
and it produces the output However, this does not work if I set term epslatex, which is the terminal that I ultimately want to use.
In fact, if I run the same script with epslatex terminal, the xtics at 10^{-3}, ... are not removed.
It seems you are trying a bit too complicated. Wouldn't the following do what you want or do you want something special and different?
Code:
### log tics and mtics
reset session
set xrange[1e-6:2]
set logscale x
set format x "10^{%T}"
set mxtics 10
set grid xtics,mxtics lt -1, lt 0
set xtics add ("" 1e-6, "" 1e-5, "" 1e-3, "" 1e-1, "1" 1)
plot x
### end of code
Result:
As for me, the epslatex output produced from your edit looks fine for me, it only contains the major xtics labeled at 10^-6, 10^-4, 10^-2 and 10^-0. Therefore this code is working perfectly (I only changed the xtics format to math so that latex doesn't complain):
set term epslatex standalone
set out "logtics.tex"
set xrange [1e-6:1]
set yrange [-1:1]
set logscale x
set format x "$10^{%T}$"
set xtics add ("" 1e-3, "" 1e-5, "" 1e-1)
set mxtics 10
set xtics nomirror
set format y ""
unset ytics
unset ylabel
p x w l lw 2 linecolor rgb "black" noti
unset out
unset term
I am using gnuplot 5.3, maybe there was some kind of bugfix in-between…
If that is not helping you, did you consider switching to cairolatex terminal? It has the same purpose, but it overcomes the troubles of converting eps to pdf prior to inclusion in pdflatex.

Problem with xrange in fill transparent plot

In the following Gnuplot:
set xlabel "Network size, m [r]" font " Helvetica,17"
set ylabel "Algorithms computation time [s]" font "Helvetica,17"
$t500 << EOD
1 0 0 0
2 0.00933135 0.0640543 0.215254
3 0.00954345 0.0746418 0.416871
4 0.009779 0.0853093 0.621712
5 0.0101225 0.0958813 0.822831
6 0.0106212 0.106193 1.02248
7 0.0114236 0.11658 1.22483
8 0.0126996 0.128502 1.42843
9 0.0150443 0.138803 1.62994
10 0.0193814 0.149177 1.83284
11 0.0282591 0.159563 2.0358
12 0.0450926 0.170019 2.24009
13 0.0791815 0.180668 2.44586
14 0.146265 0.191207 2.65134
15 0.284757 0.201806 2.85782
16 0.556054 0.212695 3.0671
17 1.11529 0.223592 3.27625
18 2.22795 0.234535 3.4873
19 4.55297 0.245686 3.69976
20 9.02265 0.257064 3.91294
EOD
set key spacing 1.0
set key top left font "Helvetica, 17"
#set xrange [2:20]
#set yrange [0.001:1000]
set logscale y
set grid
set terminal pdfcairo transparent enhanced
set style function filledcurves y1=0
set ytics ("0" 0.001,"0.01" 0.01,"0.1" 0.1,"1" 1,"10" 10,"100" 100)
unset colorbox
set style fill transparent solid 0.2 border
set bmargin 3.5
set out "program500.pdf"
plot [][] '$t500' using 1:2 title 'S computation' w filledcurves lc rgb "forest-green",\
'$t500' using 1:($2+$3) title 'S computation + Stability computation' w filledcurves lc rgb "violet",\
'$t500' using 1:($2+$4) title 'S computation + Max joint flow computation' w filledcurves lc rgb "gold"
The problem I have is set xrange [2:200] the plot changes and fills the curves upwards, like this,
I would like to know how to keep the filling below the curves as in the first plot with the default ranges and setting xrange [2:20].
"with filledcurves" allows many variants. See the documentation for help filledcurves. The default is with filledcurves closed, which tries to use the points to define a perimeter enclosing a surrounded area. If the curve runs off the edge of the plot, the edges of the plot are used to complete the perimeter. As you found, sometimes the edges chosen by the program are not the ones you wanted.
To control this, use one of the other variants. In this case you probably want with filledcurves y=0, which defines the line at y=0 as part of the perimeter.
... initial lines as above ...
set xrange [2:20]
plot'$t500' using 1:2 title 'S computation' w filledcurves y=0 lc rgb "forest-green",\
'$t500' using 1:($2+$3) title 'S computation + Stability computation' w filledcurves y=0 lc rgb "violet",\
'$t500' using 1:($2+$4) title 'S computation + Max joint flow computation' w filledcurves y=0 lc rgb "gold"

gnuplot: annotate plot with X and Y lines

I would like to plot the inverse of y=xe^x, with dashed lines leading to the point (-exp(-1), -1)
set parametric
set style arrow 1 head filled size char 1.5,20,50
set arrow 1 from -4.1,0 to 4.1,0 heads
set arrow 2 from 0,-4.1 to 0,4.1 heads
set trange[-4:4]
set xrange[-4:4]
set yrange[-4:4]
set xlabel "x"
set ylabel "y"
unset border
set xtics axis format " "
set ytics axis format " "
plot [-4:0.999] log(1-t)/t, t
plot [-4:4] t*exp(t), t lt rgb "black" title '', -exp(-1),t lt rgb "black", t, -1 lt rgb "black"
I would like to restrict the vertical line to running from y=-1 to y=0, and the horizontal line from x=-exp(-1) to x=0. How can this be done?
Also, is there an easier way to set the line colour for all plots, rather than specifying it for each one?
I see, if I'm understanding it correctly you basically need to annotate your graph with the dashed lines, so why don't you use arrows for the same too.
For example:
# I'm using pngcairo dashed terminal
set terminal pngcairo dashed
set output 'graph.png'
set parametric
set style arrow 1 head filled size char 1.5,20,50
set arrow 1 from -4.1,0 to 4.1,0 heads
set arrow 2 from 0,-4.1 to 0,4.1 heads
#set trange[-4:4]
set xrange[-4:4]
set yrange[-4:4]
set xlabel "x"
set ylabel "y"
unset border
set xtics axis format " "
set ytics axis format " "
#plot [-4:0.999] log(1-t)/t, t
set arrow from -exp(-1),-1 to -exp(-1),0 nohead lt 3
set arrow from -exp(-1),-1 to 0,-1 nohead lt 3
plot [-4:4] t*exp(t),t lt rgb "black" title ''
As far as your questions about line colours is concerned, it is also dependent on the type of terminal that you are using. For instance, with the pngcairo terminal, Gnuplot will itself assign different linestyles to plots. If you want specific colours, then offcourse you have to state them. Take a look at this link. You'll find lots of info with a simple search on Gnuplot's linestyles/linecolour/linetypes etc.

gnuplot - Filledcurve issues

I have the following gnuplot script:
#!/bin/bash
gnuplot << EOF
set term postscript portrait color enhanced
set output 'temp.ps'
set border lw 0.2
unset key
set size 1,1
set origin 0,0
set size ratio 1
set size 0.47,0.47
set mxtics 2; set mytics 4
f(x,z)=z+5-5*log10(x)
set style fill transparent solid 0.1
set yrange [12:-2]; set xrange[0:10000]
plot f(x,17.55) w filledcurve lc rgb "black", \
f(x,17.5) w lines lt 2 lc rgb "green"
EOF
Which gives me an output like this:
I need two fix two things in this image:
1- the filled zone has a black line which delimitates it and this should go away
2- the filling is covering the x and y tics and this should not happen
Thanks!
To address 1):
set style fill transparent solid 0.1 noborder
To address 2):
set grid noxtics nomxtics noytics nomytics front
As a side note, transparent in your set style fill command does nothing in the postscript terminal as it doesn't support solid transparency.

Resources