【问题标题】:grid lines are changed in multiplot if lines styles of y column is changed如果更改 y 列的线条样式,则在多图中更改网格线
【发布时间】:2016-04-13 21:07:23
【问题描述】:

我正在尝试在 png 文件中绘制多图。多图有 8 个图。每个图都有两个 y 轴,网格将用 ls 0 显示。一切正常,直到我更改图的线宽。当我直接在绘图中更改线型或线宽时,其余绘图中的网格以新的线宽和颜色显示。我在 Windows 7 MinGW 中使用 GNU Plot 版本 5。

我已经尝试过在网格中设置线条样式,如下所示:

1。 设置样式第 4 行 lc rgb 'black' lt 0 设置网格 xtics ytics y2tics ls 4

  1. 在绘图时设置线宽,如下所示: input_filename 使用 11:9 线轴 x1y2 lc rgb 'green' lw 2 title 'Plot-5'

但是没有任何效果。以下是完整代码:

#----------------
#input variables
#----------------
#input_filename 
#png_filename


#----------------
# Sample Command: 
# 
#   gnuplot -e "input_filename='test.csv'" -e "png_filename='test.png'" gnuplotMultiSample_A.plt
#
#----------------



#----------------
# Code Starts
#----------------

reset

set datafile separator ","
set term png
set output png_filename  

set size 1,2
set terminal png size 2560,1920

    set ytics nomirror
    set y2tics


    set multiplot layout 4,2 columnsfirst title png_filename

        set style line 1 lc rgb 'red' lt 3 
        set style line 2 lc rgb 'blue' lt 2 lw 2
        set style line 3 lc rgb 'green' lt 1 
        set style line 4 lc rgb 'black' lt 0 


        unset grid
        #set grid xtics ytics y2tics lt 0  lc rgb "#880000"
        set grid xtics ytics y2tics ls 4

        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:1 with lines axes x1y2 lc rgb 'green' title 'Plot-1'  

        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:3 with lines axes x1y2 ls 2 title 'Plot-2'  

        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:5 with lines axes x1y2 ls 3 title 'Plot-3'  

        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:7 with lines axes x1y2 ls 4 title 'Plot-4'  



        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:9 with lines axes x1y2 lc rgb 'green' title 'Plot-5'  

        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:11 with lines axes x1y2 lc rgb 'green' title 'Plot-6'  

        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:1 with lines axes x1y2 lc rgb 'green' title 'Plot-7'  

        plot input_filename using 11:12 with lines axes x1y1 ls 1 title 'Actual', \
                                    input_filename using 11:3 with lines axes x1y2 lc rgb 'green' title 'Plot-8'  

        unset grid

    unset multiplot

使用 pngcairo。以下是最终代码供参考。谢谢肖尔施。

#----------------
#input variables
#----------------
#input_filename 
#png_filename


#----------------
# Sample Command: 
# 
#   gnuplot -e "input_filename='test.csv'" -e "png_filename='test.png'" gnuplotMultiSample_A.plt
#
#----------------



#----------------
# Code Starts
#----------------

reset


set term pngcairo size 2560,1920
#set terminal pngcairo dashed
#set termoption dashed

set datafile separator ","
#set term png
set output png_filename  

set size 1,2
#set terminal png size 2560,1920

    set ytics nomirror
    set y2tics


    set multiplot layout 4,2 columnsfirst title png_filename

        set style line 81 lc rgb 'red' lt 3 lw 1 
        set style line 82 lc rgb 'blue' lt 2 lw 2
        set style line 83 lc rgb 'green' lt 1 lw 1 
        set style line 84 lc rgb 'black' lt 0 lw 1


        unset grid
        #set grid xtics ytics y2tics lt 0  lc rgb "#880000"
        #set grid xtics ytics y2tics lt 1 lw 1 lc rgb "#880000"     
                                        # Line type 1 works for Png but not lt 0. As per the guidelines
                                        # trying using "set terminal pngcairo dashed" as per the site: 
                                        #           http://stackoverflow.com/questions/19412382/gnuplot-line-types/19420678#19420678
                                        #           http://stackoverflow.com/questions/34689654/grid-lines-are-changed-in-multiplot-if-lines-styles-of-y-column-is-changed/34751992#34751992
        set grid xtics ytics y2tics lt 0 lw 1 lc rgb "#880000"

        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:1 with lines axes x1y2 lc rgb 'green' title 'Plot-1'  

        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:3 with lines axes x1y2 ls 82 title 'Plot-2'  

        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:5 with lines axes x1y2 ls 83 title 'Plot-3'  

        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:7 with lines axes x1y2 ls 84 title 'Plot-4'  



        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:9 with lines axes x1y2 lc rgb 'green' title 'Plot-5'  

        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:11 with lines axes x1y2 lc rgb 'green' title 'Plot-6'  

        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:1 with lines axes x1y2 lc rgb 'green' title 'Plot-7'  

        plot input_filename using 11:12 with lines axes x1y1 ls 81 title 'Actual', \
                                    input_filename using 11:3 with lines axes x1y2 lc rgb 'green' title 'Plot-8'  

        unset grid

    unset multiplot

【问题讨论】:

  • 很高兴它成功了。您不一定必须在问题中包含答案(如果您愿意,可以);但答案不会出现在问题不在的任何地方。如果它只包含您的原始代码,它可能会使您的问题更具可读性。我会把它留给你。

标签: gnuplot


【解决方案1】:

我相信您的问题与您设置的线条样式有关:

set style line 1 lc rgb 'red' lt 3 
set style line 2 lc rgb 'blue' lt 2 lw 2
set style line 3 lc rgb 'green' lt 1 
set style line 4 lc rgb 'black' lt 0

由于有预定义的线型,这些线型可能无法正常工作,最终会在多图环境中弄乱您的网格线。更具体地说,是选项lw 2 打破了您的网格线。

Printing a test outputpng terminal可以看到有80种预定义的线型:

因此,将以上行改为

set style line 81 lc rgb 'red' lt 3 
set style line 82 lc rgb 'blue' lt 2 lw 2
set style line 83 lc rgb 'green' lt 1 
set style line 84 lc rgb 'black' lt 0

并修改脚本中的plot 命令以引用这些线型编号,您将得到以下图:


调试备注:

  1. 真正搞砸情节的是lw 2 选项。奇怪的是,如果您使用lw 3 指定网格线,它们不会受到影响(但也会比您想要的更粗)。

  2. 各种组合中的dashtype 选项似乎也无法解决您的问题。对于网格线,它被完全忽略。

  3. 除一种预定义的线型外,任何其他线型都会导致此问题。您可以选择lt 8 并获得实心黑色网格线。

  4. 您可以考虑使用不同的终端:

    `set terminal pngcairo` 
    

    使用不同的终端,您的原始脚本会按预期运行。

【讨论】:

  • 是的,将线型更改为 1,正如您所展示的那样完美。但这不是我的选择。我们实际上以单色打印这些图表(这就是我们需要不同宽度的原因)并且平滑的网格线会造成混乱。我按照建议的其他页面尝试了“设置终端 pngcairo dashed”。这个问题与 lt 0 相同。而且 png 是我们浏览网页时必须的。因此,我们没有选择,而是选择离开。那是单宽多色,在基于 php 的网页上显示得很好。但是在打印输出时会产生一些混乱。
  • 嗨 Schorsch,我将线条样式更改为 81、82、83、84。并已重置代码以改用这些线条样式。如果我将 lt 1 用于网格,则一切正常。但是当我使用 lt 0 作为网格时,每当 gnuplot 绘制宽度为 2 的线时,它会更改宽度为 2 的整个网格,直到我们再次用 lt 0 重新绘制一条线并将宽度指定为 1。我已经编辑了代码并更新了帖子。如果我误解了你的建议,我很高兴得到纠正。 :) 再次感谢您帮助我。
  • 在我添加的新代码中,在绘制第二个宽度为 2 的绘图后,绘图 3 和 4 的网格宽度为 2。现在,因为我已经绘制了具有 lt 0 的绘图 4,并且使用宽度大小为 1,网格从绘图 5 恢复正常。绘图首先在第 1 列(1 到 4)中编号,然后在第 2 列(1 到 4)中编号。因此,通过 plot-3,我的意思是第一列中的第三个图。 :-)
  • @SunilVerma - 您必须删除其他 set termset terminal 命令,否则,您将重置为 png 而不是 pngcairo(因此出现问题)。另外,我认为从版本 5 开始,终端的 dashed 选项不再起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多