Sunil Verma
Sunil Verma

Reputation: 71

grid lines are changed in multiplot if lines styles of y column is changed

I am trying to plot multiplots in png files. Multiplot has 8 plots. Each plot has two y-axis and grid is to be displayed with ls 0. Everything works fine until I change the line width of a plot. When I change line style or line width directly in the plot, the grids in rest of the plots are displayed with the new line width and color. I am using GNU Plot version 5 in Windows 7 MinGW.

Things I have already tried is setting the line style in grid like below:

1. set style line 4 lc rgb 'black' lt 0 set grid xtics ytics y2tics ls 4

  1. Setting the line width while plotting like below: input_filename using 11:9 with lines axes x1y2 lc rgb 'green' lw 2 title 'Plot-5'

enter image description here

But nothing works. Below is the full code:

#----------------
#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

Working with pngcairo. Below is the final code for reference. Thanks Schorsch.

#----------------
#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

Upvotes: 2

Views: 986

Answers (1)

Schorsch
Schorsch

Reputation: 7925

I believe your issue is related to the line styles you set:

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

As there are predefined line styles, these may not work properly and ultimately mess up your grid lines in the multiplot environment. More specifically, it is the option lw 2 that breaks your grid lines.

Printing a test output for the png terminal you can see that there are 80 predefined line styles:

test for png terminal

Therefore, changing the above lines to

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

and modifiying the plot commands in your script to reference these line style numbers, you get this plot:

new plot


Debugging remarks:

  1. What really appears to mess up the plot is the lw 2 option. Oddly, if you specified your grid lines with lw 3, they would not be affected (but also be thicker than you'd like).

  2. The dashtype option in various combinations does not appear to fix your issue, either. For the grid lines it is outright ignored.

  3. Anything but one of the predefined line types causes this issue. You could pick lt 8 and get solid black grid lines.

  4. You could consider using a different terminal:

    `set terminal pngcairo` 
    

    With that different terminal, your original script behaves as expected.

Upvotes: 2

Related Questions