2
votes

I'm pretty new to gnuplot, so I'm thankful for every advice.

Right now, I am trying to plot some data using the logscale command. But I don't know why all the xtics disappear when I use the logscale. This is the script I use:

#creates a plot of all the four different loops with a logscale. Fits the functions as well and saves the fitting data
#in a file named fitting.dat

set size 1,1
# set logscale
set logscale y 10
set logscale x 10
#set xlabel and y label
set xlabel "Dimension of Matrix"
set ylabel "time [s]"
#scale plot
set xrange [450:850]
set yrange[0.01:5]
#nothing displayed from fitting
set fit quiet
#position of legend
set key  top right
set key horizontal
# guessing the parameters, the fit will be better and we know that the exponent should be \approx 3
b=3
d=3
f=3
h=3
#Define all th four different data fitting functions, asuming f(x) ~  a*x^b
f(x)= a*x**b
g(x)=c*x**d
h(x)=e*x**f
j(x)=g*x**h

#fit the different functions
fit f(x) 'matmul.txt' using 1:2 via a,b
fit g(x) 'matmul.txt' using 1:3 via c,d
fit h(x) 'matmul.txt' using 1:4 via e,f
fit j(x) 'matmul.txt' using 1:5 via g,h
# save the fitting parameters in an extra file
set print 'fitting.dat'
    print 'function'
    print a,'*x', '**', b , '       rows'
    print c,'*x', '**', d , '       cols'
    print e,'*x', '**', f , '       intrinsic function'
    print g,'*x', '**', h , '       lapack routine'

# plot everything
plot    "matmul.txt" u 1:2 t "rows" ,\
    "matmul.txt"  u 1:3 t "cols" ,\
    "matmul.txt"  u 1:4 t "intrinsic" ,\
    "matmul.txt" u 1:5 t "lapack" ,\
    f(x) t sprintf("row:%.2e*x^(%.2f)", a,b),\
    g(x) t sprintf("col:%.2e*x^(%.2f)",c,d),\
    h(x) t sprintf("int:%.2e*x^(%.2f)",e,f),\
    j(x) t sprintf("lap:%.2e*x^(%.2f)",g,h)
 #choose output format
 set terminal png
 set output "time.png"
 replot
#now, non-logarithmic plot
#unset logscale
set yrange[0.01:1]
unset logscale
#plot again
plot    "matmul.txt" u 1:2 t "rows" ,\
    "matmul.txt"  u 1:3 t "cols" ,\
    "matmul.txt"  u 1:4 t "intrinsic" ,\
    "matmul.txt" u 1:5 t "lapack" ,\
    f(x) t sprintf("col:%.2e*x^(%.2f)", a,b),\
    g(x) t sprintf("row:%.2e*x^(%.2f)",c,d),\
    h(x) t sprintf("int:%.2e*x^(%.2f)",e,f),\
    j(x) t sprintf("lap%.2e*x^(%.2f)",g,h)

My Input file 'matmul.txt' looks like this:

#Dim   rows       cols     intrinsic  lapack
500 0.1320E+00 0.1040E+00 0.6800E-01 0.2000E-01
520 0.1400E+00 0.1320E+00 0.5600E-01 0.2000E-01
540 0.1480E+00 0.1400E+00 0.6000E-01 0.3200E-01
560 0.1680E+00 0.1480E+00 0.7200E-01 0.2400E-01
580 0.1800E+00 0.1680E+00 0.6800E-01 0.3200E-01
600 0.1920E+00 0.1960E+00 0.7200E-01 0.3600E-01
620 0.2080E+00 0.2040E+00 0.9600E-01 0.2000E-01
640 0.4000E+00 0.3520E+00 0.8400E-01 0.3200E-01
...

Now, If I run this file, I obtain the following output plot

I don't know why, but the range of the yscale is not correct and the xtics are not displayed. If I plot it without 'logscale', the plot is exactly what I want. Why doesn't this work?

2
To track that down, please shorten you script to the minimum where you can see this: a single plot, no fitting, no printing etc. BTW: why do you plot three times for a single image? set terminal... set output ... plot, done.Christoph

2 Answers

3
votes

Tics in logarithmic plots are not separated by a constant summand as in 1, 2, 3, ..., they are separated by a constant factor as in 1, 10, 100, ...

This means in your case for the y-axis: You have given the range [0.01:5], leading to tics at 0.01, 0.1, 1 as it is seen in the picture. Above 1, you have minor tics at 2, 3, 4, and 5. 5 is the upper boundary of the graph as specified in the range. To also have a label at this tic, just add it with:

set ytics add (5)

or change the yrange to one of

set yrange [0.01:1]
set yrange [0.01:10]

For your xtics: Labels would be at 1, 10, 100, 1000, ... But your range is from 450 to 850: no labeled xtic inside.

Again, you can set them manually:

set xtics (450, 550, 650, 750, 850)
2
votes

Your x-axis spans less than a decade and the default major tic frequency is a decade. If you want labeled tics within this range use set xtics (400,500,600,700,800) or whatever you want.

This is all in the documentation, just search for "logscale"