Gnuplot线条类型无法更改。

5

请问您能帮我吗?我想把一行的类型改为虚线。我使用以下命令:

gnuplot> set terminal png size 750,210 nocrop butt font "/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf" 8
gnuplot> set output "/root/data.png"
gnuplot> set xdata time
gnuplot> set timefmt "%Y-%m-%d"
gnuplot> set format x "%b %d"
gnuplot> set ylabel "item1"
gnuplot> set y2label "item2"
gnuplot> set y2tics
gnuplot> set datafile separator "|"
gnuplot> plot "/root/results.txt" using 1:2 title "item1" w lines lt 4, "/root/results.txt" using 1:3 title "item2" with lines

但我总是只得到品红色的线。

我使用的是4.6补丁级别0版本。

谢谢回复。


http://stackoverflow.com/q/8106872/1030675 - choroba
@choroba,谢谢。但是请问我如何在绘图语法中设置线条样式? - Mato
plot x lt 4, x**2 lt 3有什么问题?但是plot x lt 4, x**2也应该可以工作,但在第二种情况下,会自动选择linetype 2 - Christoph
@Christoph 谢谢。但是当我使用以下命令时: gnuplot> set style line 1 lt 2 lc 8 gnuplot> set style line 1 lt 1 lc 7 gnuplot> plot "/root/dataASD.txt" using 1:2 title "item1" with lines, "/root/dataASD.txt" using 1:3 title "item2" with lines 我仍然得到相同的结果... 线条是实心的,第一条是红色的,第二条是绿色的... - Mato
是的,因为使用 set style line 您可以指定一条线的样式,并且可以通过例如 linestyle 1 来选择。当没有指定任何内容时,默认使用线类型 - Christoph
一样的问题。我可以输入lw 4,它可以工作,但是lt 2不行。我似乎只能画直线。 - SDsolar
2个回答

5

使用set命令有几种改变行颜色的方法:

  1. Define line styles:

    set style line 1 linetype 1 linecolor 7
    set style line 2 linetype 1 linecolor rgb "#dd7700"
    plot x linestyle 1, x**2 linestyle 2
    

    You must explicitely specify which line style is used.

  2. Choose and increment over line style instead of line type if nothing is specified:

    set style line 1 linetype 1 linecolor 7
    set style line 2 linetype 1 linecolor rgb "#dd7700"
    set style increment user
    plot x, x**2
    
  3. Redefine the default line type (introduced in version 4.6.0):

    set linetype 1 linecolor 7
    set linetype 2 linetype 1 linecolor rgb "magenta"
    plot x, x**2
    

    Beware, that unlike line styles, redefinitions by set linetype are persistent; they are not affected by reset. To reset them you must use set linetype 1 default.

所以,一个最简单的绘图脚本可能如下所示:
reset
set terminal pngcairo dashed monochrome
set output "/root/data.png"
set xdata time
set timefmt "%Y-%m-%d"
set format x "%b %d"
set datafile separator "|"
set style data lines

plot "/root/results.txt" using 1:2 linetype 1, "" using 1:3 linetype 3

谢谢。但是现在我的正确绘图命令应该是什么?如果我使用set 1,当我使用以下命令时: plot "/root/dataASD.txt" linestyle 1 using 1:2 title "item1" with lines, "/root/dataASD.txt" linestyle 2 using 1:3 title "item2" with lines 我会收到错误消息:需要x时间数据的完整using规范。 - Mato
请参考编辑后的答案,其中包含了完整的脚本。这个脚本应该可以正常运行,并且不会改变关于时间数据处理的任何内容。在执行代码之前,请确保在交互式会话中加入 reset 以避免之前设置的问题。 - Christoph
谢谢。它有效。但第二行没有点。我设置了线型4。 线型4应该是虚线 - http://www2.yukawa.kyoto-u.ac.jp/~akira.ohnishi/Lib/gnuplot.html 但我仍然有实线。请问为什么?我需要一条虚线,因为图形将使用单色打印... - Mato
哎呀,我一直使用“品红”颜色,但没有注意到“虚线”的部分!你必须使用带有“虚线”选项的pngcairo终端来完成这个任务,因为使用png(即libgd)无法得到虚线。例如,使用set terminal pngcairo dashed monochrome; set output 'test.png'; plot "/root/results.txt" using 1:2 lt 1 , "" using 1:3 lt 3来获得黑色虚线,也可以参考Gnuplot line types - Christoph
如果我使用: gnuplot> set terminal pngcairo dashed monochrome 终端类型设置为'pngcairo' 选项是' background "#ffffff" fontscale 1.0 monochrome dashed size 640, 480 ' gnuplot> set output 'bodkaD1.png' gnuplot> set xdata time gnuplot> set timefmt "%Y-%m-%d" gnuplot> set format x "%b %d" gnuplot> set datafile separator "|" gnuplot> plot "/root/dataASD.txt" using 1:2 title "item1" lt 1, "/root/dataASD.txt" using 1:3 title "item2" lt 3 我会得到散点加星号符号的图形。 - Mato
显示剩余3条评论

0
在X-11终端上,我没有问题改变线条颜色,但是无法成功更改线型以包括点状和/或虚线。

4
在 gnuplot 5 中,你必须使用 dashtype 来获得虚线或点状线,请参考例如 https://dev59.com/s2Ik5IYBdhLWcg3wTcYr#19420678、https://dev59.com/Zofca4cB1Zd3GeqPmrzW#28438812 或 http://stackoverflow.com/a/29950759/2604213 获取实际示例和语法解释。 - Christoph
非常感谢。我明白他们在说什么。我会测试一下。点赞你的评论。 - SDsolar

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