我对 gnuplot 还很陌生,所以我很感谢每一个建议。
现在,我正在尝试使用 logscale 命令绘制一些数据。但我不知道为什么当我使用对数刻度时所有 xtics 都会消失。这是我使用的脚本:
#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)
Run Code Online (Sandbox Code Playgroud)
我的输入文件“matmul.txt”如下所示:
#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
...
Run Code Online (Sandbox Code Playgroud)
现在,如果我运行该文件,我将获得以下输出图
我不知道为什么,但是 yscale 的范围不正确,并且 xtics 没有显示。如果我在没有“对数刻度”的情况下绘制它,则该图正是我想要的。为什么这不起作用?
对数图中的抽动不是像 1, 2, 3, ... 中一样由常数被加数分隔,而是由常数因子分隔,如 1, 10, 100, ...
这意味着在您的 y 轴情况下:您已经给出了范围[0.01:5],导致抽动为 0.01, 0.1, 1,如图所示。高于 1 时,在 2、3、4 和 5 处会出现轻微抽动。5 是范围中指定的图形上限。要在此标记处也有一个标签,只需添加它:
set ytics add (5)
Run Code Online (Sandbox Code Playgroud)
或将 yrange 更改为其中之一
set yrange [0.01:1]
set yrange [0.01:10]
Run Code Online (Sandbox Code Playgroud)
对于您的 xtic:标签将为 1、10、100、1000,...但您的范围是从 450 到 850:内部没有标记 xtic。
同样,您可以手动设置它们:
set xtics (450, 550, 650, 750, 850)
Run Code Online (Sandbox Code Playgroud)