使用set format x
;
set terminal pngcairo enhanced color dashed \
rounded size 1200,500
set title "Akamai"
set xlabel "date"
set xdata time
set timefmt "%d-%m-%Y"
set format x "%d/%m\n%Y"
set xtics 86400
set nomxtics
set ylabel "Total Petitions (%)"
set yrange [95:100]
set style data linespoints
set grid
set key right bottom
set output 'user1847844.png'
plot "datos.csv" using 1:2 title "One (%)", \
"" using 1:3 title "Two (%)", \
"" using 1:4 title "Ideal (%)"
在内部,gnuplot
将日期时间转换为秒。所以行set xtics 86400
基本上说,每天有一个刻度,因为一天有24 * 60 * 60 = 86400秒。 set nomxtics
告诉gnuplot在x轴上不显示小刻度标记。
这给:
如果要旋转的标签,使用:
set format x "%d/%m/%Y"
set xtics rotate 86400
这应该格式中的日期为单线,旋转90度的标签。
更新:
请注意,我使用的是pngcairo
终端。这是基于cairo graphics library。这旨在为所有输出介质提供一致的输出。但gnuplot
必须编译与开罗支持这个工作。
一般来说,我更喜欢pdfcairo
终端。这产生PDF输出,可以缩放而不会产生像素化效应。
更新2:
希望能在我的图表一致性,我在我的gnuplotrc
,我在我的图表使用定义的某些风格。我的gnuplotrc的内容如下所示。
set encoding utf8
# See https://github.com/Gnuplotting/gnuplot-palettes
# Line styles (colorbrewer Set1)
set style line 1 lc rgb '#E41A1C' pt 1 ps 1 lt 1 lw 2 # red
set style line 2 lc rgb '#377EB8' pt 6 ps 1 lt 1 lw 2 # blue
set style line 3 lc rgb '#4DAF4A' pt 2 ps 1 lt 1 lw 2 # green
set style line 4 lc rgb '#984EA3' pt 3 ps 1 lt 1 lw 2 # purple
set style line 5 lc rgb '#FF7F00' pt 4 ps 1 lt 1 lw 2 # orange
set style line 6 lc rgb '#FFFF33' pt 5 ps 1 lt 1 lw 2 # yellow
set style line 7 lc rgb '#A65628' pt 7 ps 1 lt 1 lw 2 # brown
set style line 8 lc rgb '#F781BF' pt 8 ps 1 lt 1 lw 2 # pink
# Palette
set palette maxcolors 8
set palette defined (0 '#E41A1C', 1 '#377EB8', 2 '#4DAF4A', 3 '#984EA3',\
4 '#FF7F00', 5 '#FFFF33', 6 '#A65628', 7 '#F781BF')
# Standard border
set style line 11 lc rgb '#808080' lt 1 lw 3
set border 0 back ls 11
set tics out nomirror
# Standard grid
set style line 12 lc rgb '#808080' lt 0 lw 1
set grid back ls 12
unset grid
而且我使用一个pdfcairo
终端作为标准,就像这样。
set terminal pdfcairo enhanced color dashed font "Alegreya, 14" \
rounded size 16 cm, 9.6 cm
使用的字体是一个例子。对于报告中的图表,我倾向于使用与正文相同的字体。
plot
命令使用定义的样式。
plot "user1847844.d" using 1:2 ls 1 title "One (%)", \
"" using 1:3 ls 2 title "Two (%)", \
"" using 1:4 ls 3 title "Ideal (%)"
这产生了一个像这样的图。
注:由于StackOverflow上不接受PDF图像,我使用ImageMagick将它转换为PNG。
convert -density 300 <input.pdf> -quality 100 -sharpen 0x1.0 <output.png>