No mxtics in logscale with gnuplot - 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.

Related

Gnuplot: logscale y moves x axis labels and inverts y axis when using view map

I stumbled across some behavior in Gnuplot 5.2 patchlevel 2, and I can't find if it's a bug or a feature:
I want to plot a heat map, but when I set the y axis to logscale the axis inverts and all labels of the x axis are moved to the upper part of the plot with the xlabel inside the plot. Also the the y axis gets inverted. If instead I only set logscale x then nothing unexpected happens. This seems to be linked to "set view map". If I omit this line then it works as expected (just not as needed).
Does anyone know what might be the problem?
EDIT: Turns out, this is a bug in 5.2.2 . It doesn't happen in later versions anymore.
set terminal "pdfcairo" enhanced dashed size 10,5
set termoptions font "Helvetica,15"
set palette defined (-3 "#1E90FF", 1 "#FFFACD", 4 "#CD5C5C")
set view map
set xlabel "x"
set ylabel "y"
set cblabel "x*y"
set output "table.pdf"
set multiplot
set size .45,1.0
set origin .0,.0
splot 'table.dat' using 1:2:3 with pm3d notitle
set logscale y
set size .45,1.0
set origin .5,.0
replot
unset multiplot
unset output
exit

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:

Hide the tics behind a 3D figure in GNUPLOT

I am trying to draw a figure using some perspective in GNUPLOT. I have already used set xyplane at 0 to add the perspective effect. The problem now is that the tics appear in front of my sphere. For a 3D effect, I want the sphere to obstruct some of the tics, leaving them in the background (the ones on the y and x axis). I tried using set tics back but it doesn't work.
Here is the code:
# set term x11 0
set xlabel 'X'
set ylabel 'Y'
set zlabel 'Z'
set title 'Ray on Sphere 2'
set parametric
set isosamples 50,50
set hidden
set view 120, 200
set view equal
R = 3e-6
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
set xyplane at 0
set xtics back
splot R*cos(u)*cos(v),R*cos(u)*sin(v)-1.5e-6,R*sin(u) w l lc rgb 'yellow' title 'Silica Particle',\
'-' w p title 'Incidence Point'
and the result:
I think your best bet is to move the tic labels to the other side of the plot.
# All as before
set xlabel 'X'
set ylabel 'Y'
set zlabel 'Z'
set title 'Ray on Sphere 2'
set parametric
set isosamples 50,50
set hidden
set view 120, 200
set view equal
R = 3e-6
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
set xyplane at 0
# Now a change in the tic label placement
set xtics offset graph 0, 1.2
set ytics offset graph -1.2, 0
set xlabel offset graph 0, 1.5
set ylabel offset graph -1.5, 0
splot R*cos(u)*cos(v),R*cos(u)*sin(v)-1.5e-6,R*sin(u) w l lc rgb 'yellow' title 'Silica Particle'
I'm sure you can make it nicer by tweaking the placement, the font size, etc
Your view setting is a bit strange for me.
With set view 60,160 it looks like this
One can play with the view interactively and read the setting from the bottom bar.

Why is output.eps 0kb?

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

increment of ytics in gnuplot

I plotted a graph and I'd like to show ytics as a function of x. For example:
I plot x^2 and I'd like to show ytics for 0,1,4,9... . Is there any way to do this automatically or I have to set manually every tic in y-axis? I tried to set a function when defining ytics but gnuplot doesn't accept it.
Thanks for any help
You can use a for loop. Of course, here you need to know your x-range in advance:
f(x)=x**2
set ytics ( sprintf('%f',f(-10)) f(-10) )
set for [i=-9:10] ytics add ( sprintf('%f',f(i)) f(i) )
plot f(x)
Here is my semiautomatic answer, using a for loop to build the ytics string:
#!/usr/bin/env gnuplot
set terminal pngcairo
set output 'test.png'
# x range
xmin = 0
xmax = 10
set xrange [xmin:xmax]
# define function of x to make plot, define tics
yfn(x) = x**2
# integer counting over tic positions
imin = int(xmin)
imax = int(xmax)
# build tics string
tix = '("'.sprintf('%d', yfn(imin)).'" '.sprintf('%d', yfn(imin))
do for [i=(imin+1):imax] {
tix = tix.', "'.sprintf('%d', yfn(i)).'" '.sprintf('%d', yfn(i))
}
tix = tix.')'
set macros
# set ytics using macro expansion
set ytics #tix
plot yfn(x)
This is the result:
i do not answer quite exactly to your question,
Although, that makes me think of customising the label of ytis.
Example :
f(x)=x**2
f1(x)=sqrt(abs(x))
set ytics format ""
set ytics scale 1
set t qt 0 enhanced font "Sans,9"
#set mytics 8
# ploting once the function for getting the GPVAL_ variable
plot f(x) t "f(x)=x**2"
# calculating function for the list of increment
linRg(start,end,increment)=system(sprintf("seq %g %g %g", start, increment, end))
# forcing the tics, otherwise, the tics of the first plot will still be marked
set ytics GPVAL_Y_MIN, (GPVAL_Y_MAX-GPVAL_Y_MIN)/8, GPVAL_Y_MAX
do for [i in linRg(GPVAL_Y_MIN, GPVAL_Y_MAX, (GPVAL_Y_MAX-GPVAL_Y_MIN)/8)] { pr i; set ytics add ('f(|'.gprintf("%.1s%c",f1(i)).'|)'.gprintf("=%.1s%c",i) i)}
replot
will produced :

Resources