gnuplot的PNG输出无法绘制虚线/点状线。

18

我正在尝试使用gnuplot v4.4绘制同时包含虚线和实线的图形。 代码如下:

set term postscript eps enhanced color
set style line 1 linetype 1 lw 2
set style line 2 linetype 1 lw 2 linecolor rgb 'green'
set style line 3 linetype 1 lw 2 linecolor rgb 'blue'
set style line 4 linetype 4 lw 2 linecolor rgb 'red'
set style line 5 linetype 3 lw 2 linecolor rgb 'blue'

set border lw 3
set xtics font ',18'
set ytics font ',18'
set output 'roc.ps'
set key right bottom
plot 'roc_fpdock_isc_test' u 1:2 w l ls 1 title "Full optimization, test set" ,x w l ls 2 title "Random", 'roc_fpdock_isc_training' u 1:2 w l ls 3 title "Full optimization, training set", 'roc_mini_pep_sc_training' u 1:2 w l ls 4 title "Minimization only, training set", 'roc_mini_pep_sc_test' u 1:2 w l ls 5 title "Minimization only, test set"

问题是,我无法将它绘制为png格式。当我将set term指令更改为:set term png enhanced时,我只得到了连续的线条。你有什么想法是怎么出错的吗?

2个回答

29

事实证明,我似乎无法在 png 终端中获得虚线(使用 GD 后端)。但是,如果您有cairo终端,您可以获取带有虚线的png图像(假设您选择了适当的线型)。

set term pngcairo dashed
set output "foo.png"
test
!display foo.png
!rm foo.png

顺便提一下,test非常适合查询特定终端的行为。


2
如果您有pngcairo,我建议您使用它。根据我的经验,它比带有GD后端的png制作出更漂亮的图表。 - mgilson
1
谢谢!在遇到相同的PNG问题后,它节省了一些时间。 - Lucas Ponce
到了2022年,同样的问题仍然存在(gnuplot 5.4)!这个答案真是救星。我意识到test真的很棒。 - Masa Sakano

3

在pngcairo中,您可以使用dt选项设置虚线类型。图例如下:

Legend

例如:

set style line 5 linetype 3 dt 5 lw 3 linecolor rgb 'green' 

设置虚线类型为5


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接