如何使用Gnuplot从文件中绘制特定于直方图的值

如何使用Gnuplot从文件中绘制特定于直方图的值,plot,conditional,gnuplot,histogram,Plot,Conditional,Gnuplot,Histogram,我想为直方图绘制两个条形图,一个取决于文件的第一行,另一个取决于第二行。例如,假设有如下CSV文件: 1 0.5 2 0.7 我想绘制值为0.5的第一条蓝色条和值为0.7的第二条红色条 到目前为止,我已经编写了以下脚本(我有一个multiplot,因为我需要绘制4个相等属性的图形): 我尝试过类似于“的解决方案,我更改了此表单中的每个CSV: R1 R2 0.5 0.7 还有我的剧本: #!/usr/bin/env gnuplot set term pngcairo enhanced siz

我想为直方图绘制两个条形图,一个取决于文件的第一行,另一个取决于第二行。例如,假设有如下CSV文件:

1 0.5
2 0.7
我想绘制值为0.5的第一条蓝色条和值为0.7的第二条红色条

到目前为止,我已经编写了以下脚本(我有一个multiplot,因为我需要绘制4个相等属性的图形):


我尝试过类似于
“的解决方案,我更改了此表单中的每个CSV:

R1 R2
0.5 0.7
还有我的剧本:

#!/usr/bin/env gnuplot
set term pngcairo enhanced size 1500,700
set output 'accuracy_plot.png'
set multiplot layout 1,4
set xlabel 'rounds' font ',16'
set ylabel 'mean' font ',16'
set xrange[1:2]
set yrange[0:1.5]
set style fill solid
set grid xtics lt 0 lw 1 lc rgb "#333333"
set grid ytics lt 0 lw 1 lc rgb "#333333"
set xtics font ',14'
set xtics autofreq 1
set ytics font ',14'
set key font ',12'
set title font ',20'

set style data histograms
set style histogram columnstacked

###
set title 'Q1'
plot "q1.csv" using 1 lt 1 title columnhead, \
newhistogram lt 1 at 1, '' u 1 ti col, \
newhistogram lt 2 at 2, '' u 2 ti col, \
"truth1.csv" using 1:2 title 'truth' with lines linewidth 3 linecolor rgb 'black'
###
set title 'Q2'
plot "q2.csv" using 1 lt 1 title columnhead, \
newhistogram lt 1 at 1, '' u 1 ti col, \
newhistogram lt 2 at 2, '' u 2 ti col, \
"truth1.csv" using 1:2 title 'truth' with lines linewidth 3 linecolor rgb 'black'
###
set title 'Q3'
plot "q3.csv" using 1 lt 1 title columnhead, \
newhistogram lt 1 at 1, '' u 1 ti col, \
newhistogram lt 2 at 2, '' u 2 ti col, \
"truth1.csv" using 1:2 title 'truth' with lines linewidth 3 linecolor rgb 'black'
###
set title 'Q4'
plot "q4.csv" using 1 lt 1 title columnhead, \
newhistogram lt 1 at 1, '' u 1 ti col, \
newhistogram lt 2 at 2, '' u 2 ti col, \
"truth1.csv" using 1:2 title 'truth' with lines linewidth 3 linecolor rgb 'black'
###
unset multiplot
这是结果(具有实际值):


您不需要发布TIC、标签和倍增的所有设置来显示问题

您可以使用例如
linecolor变量
根据第一列中的值选择不同的线型:

set terminal png enhanced
set output 'foobar.png'

set yrange [0:1]
set style fill solid

set linetype 1 lc rgb 'blue'
set linetype 2 lc rgb 'red'

plot 'q1.csv' using 1:2:1 with boxes lc variable notitle


请注意,
set linetype
的更改不会通过
reset
恢复,但您必须重新启动gnuplot(版本5.0将为此提供一个
reset session
选项)。

谢谢。您的解决方案比我的好!
set terminal png enhanced
set output 'foobar.png'

set yrange [0:1]
set style fill solid

set linetype 1 lc rgb 'blue'
set linetype 2 lc rgb 'red'

plot 'q1.csv' using 1:2:1 with boxes lc variable notitle