来自此 CSV 输入的 Gnuplot 条形图
Gnuplot bar chart from this CSV input
我有 csv 文件 data.dat 例如这些值:
#W=1
0;sqlite;11500
1;hsql;14550
2;h2;17550
#W=2
0;sqlite;11000
1;hsql;13800
2;h2;16500
#W=3
0;sqlite;11000
1;hsql;13800
2;h2;16500
#W=4
0;sqlite;11000
1;hsql;13800
2;h2;16500
我需要将条形图绘制成 pdf。每个图表的每个数据都以标题#W1、#W2....
开头
我试过这个脚本:
cat << __EOF | gnuplot -persist
set terminal pdf
set output 'out.pdf'
set datafile separator ";"
set boxwidth 0.5
set style fill solid
plot "data2.dat" using 1:3:xtic(2) with boxes
__EOF
给出这个输出:
我怎样才能从一个数据文件中制作更多的图表(在这个例子中是 4 个,但可能更多或更少),每个图表分别位于前一个图表之下?
编辑:
每个图形可以有不同数量的条,而不仅仅是前面示例中的三个。文件 data2.dat 也可能如下所示:
#W=1
0;sqlite;11500
1;hsql;14550
2;h2;17550
3;derby;8500
4;sqlite;13550
5;h2;19250
#W=2
0;sqlite;11000
1;hsql;13800
当每个图表有 3 个条形图时,Miguel answer 的这个脚本工作正常,但我不知道如何更改它以绘制更多或更少的条形图。
cat << __EOF | gnuplot -persist
set terminal pdf
set datafile separator ";"
set boxwidth 0.5
set style fill solid
do for [i=0:3] {
set output 'out'.i.'.pdf'
plot "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
}
__EOF
另外,如果可能的话,我想根据每个数据集的 header 值(W=1,W=2....)
绘制图表标题
您可以使用 multiplot
和 plot
命令的外部循环,或者您可以在 plot
命令内迭代,具体取决于您想要实现的目标。 every
选项允许您 select 从您的文件中绘制什么。
与multiplot
:
set multiplot layout 2,2
set datafile separator ";"
set boxwidth 0.5
set style fill solid
do for [i=0:3] {
plot "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
}
在一个地块内:
set datafile separator ";"
set boxwidth 0.5
set style fill solid
plot for [i=0:3] "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
在您的情况下,由于文件中的最后 3 个块是相同的,因此您无法在第 2 块和第 3 块上方进行可视化,它们仍然隐藏在第 4 块下方。
要再次在独立文件中绘制图表,您只需循环,但现在每次迭代都更改文件名:
set terminal pdf
set datafile separator ";"
set boxwidth 0.5
set style fill solid
do for [i=0:3] {
set output 'out'.i.'.pdf'
plot "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
}
以上代码将生成文件out0.pdf
、out1.pdf
等
我有 csv 文件 data.dat 例如这些值:
#W=1
0;sqlite;11500
1;hsql;14550
2;h2;17550
#W=2
0;sqlite;11000
1;hsql;13800
2;h2;16500
#W=3
0;sqlite;11000
1;hsql;13800
2;h2;16500
#W=4
0;sqlite;11000
1;hsql;13800
2;h2;16500
我需要将条形图绘制成 pdf。每个图表的每个数据都以标题#W1、#W2....
开头我试过这个脚本:
cat << __EOF | gnuplot -persist
set terminal pdf
set output 'out.pdf'
set datafile separator ";"
set boxwidth 0.5
set style fill solid
plot "data2.dat" using 1:3:xtic(2) with boxes
__EOF
给出这个输出:
我怎样才能从一个数据文件中制作更多的图表(在这个例子中是 4 个,但可能更多或更少),每个图表分别位于前一个图表之下?
编辑: 每个图形可以有不同数量的条,而不仅仅是前面示例中的三个。文件 data2.dat 也可能如下所示:
#W=1
0;sqlite;11500
1;hsql;14550
2;h2;17550
3;derby;8500
4;sqlite;13550
5;h2;19250
#W=2
0;sqlite;11000
1;hsql;13800
当每个图表有 3 个条形图时,Miguel answer 的这个脚本工作正常,但我不知道如何更改它以绘制更多或更少的条形图。
cat << __EOF | gnuplot -persist
set terminal pdf
set datafile separator ";"
set boxwidth 0.5
set style fill solid
do for [i=0:3] {
set output 'out'.i.'.pdf'
plot "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
}
__EOF
另外,如果可能的话,我想根据每个数据集的 header 值(W=1,W=2....)
绘制图表标题您可以使用 multiplot
和 plot
命令的外部循环,或者您可以在 plot
命令内迭代,具体取决于您想要实现的目标。 every
选项允许您 select 从您的文件中绘制什么。
与multiplot
:
set multiplot layout 2,2
set datafile separator ";"
set boxwidth 0.5
set style fill solid
do for [i=0:3] {
plot "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
}
在一个地块内:
set datafile separator ";"
set boxwidth 0.5
set style fill solid
plot for [i=0:3] "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
在您的情况下,由于文件中的最后 3 个块是相同的,因此您无法在第 2 块和第 3 块上方进行可视化,它们仍然隐藏在第 4 块下方。
要再次在独立文件中绘制图表,您只需循环,但现在每次迭代都更改文件名:
set terminal pdf
set datafile separator ";"
set boxwidth 0.5
set style fill solid
do for [i=0:3] {
set output 'out'.i.'.pdf'
plot "data2.dat" using 1:3:xtic(2) every ::(i*3)::(i*3+3) with boxes
}
以上代码将生成文件out0.pdf
、out1.pdf
等