2

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
Sunil Verma
  • 71
  • 2
  • 7
  • Glad it worked. You do not necessarily have to include the answer in your question (you can if you want); but the answer isn't going anywhere the question isn't. It might make your question more readable, if it only contained your original code. I'll leave that to you. – Schorsch Jan 14 '16 at 19:16

1 Answers1

2

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.

Community
  • 1
  • 1
Schorsch
  • 7,761
  • 6
  • 39
  • 65
  • Yes, changing the line type to 1, works perfectly as you have shown. But that is not an option for me. We actually print these graphs in monochrome (that's why we need different widths) and smooth grid lines creates confusion. I tried "set terminal pngcairo dashed" as per the other page suggested. The issue is the same with lt 0. And png is a must for us for webpage views. So, we are not left with a choice rather than to leave with it. That is single width multi-color, shows very well on php based webpages. But on printout creates a bit confusion though. – Sunil Verma Jan 14 '16 at 13:32
  • Hi Schorsch, I changed the lines styles to 81,82,83,84. And have reset the code to use these line styles instead. Things works perfectly fine, if I use lt 1 for grid. But when I use lt 0 for the grids whenever gnuplot draws a line with width 2, it changes the whole grid with width 2 until we redraw a line again with lt 0 and specify the width to be 1. I have edited the code and updated the post. If I misunderstood your suggestion, I would be glad to be corrected. :) Thanks again for helping me. – Sunil Verma Jan 14 '16 at 14:47
  • In the new code I added, after drawing 2nd plot which is of width 2, grids of plots 3 and 4 are with width 2. Now, since I have drawn plot 4 with lt 0, and with width size 1, grid is restored to normal from plot 5. Plots are numbered first in column-1 (1 to 4) and then in columns-2 (1 to 4). Thus, by plot-3, I mean 3rd plot in first column. :-) – Sunil Verma Jan 14 '16 at 14:51
  • 1
    Regarding dashed lines with gnuplot 5 see [gnuplot line types](http://stackoverflow.com/a/19420678/2604213), [How to produce dashed lines in gnuplot 5 using TikZ terminal?](http://stackoverflow.com/a/28438812/2604213) and [Exact meaning of dashtype index in the Gnuplot 5.0?](http://stackoverflow.com/a/29950759/2604213) – Christoph Jan 14 '16 at 15:02
  • I miss the FB "like" button on StackOverflow. :-) Cool, the pointers looks awesome. I will give it a try. @Schorsch, we want images for php webpages. So, terminal type can only be png or jpeg. – Sunil Verma Jan 14 '16 at 17:05
  • @Schorsch, I tried pngcairo. But the result was same with lt 0 grid. I have added the new code with it (two lines shown below). "set terminal pngcairo dashed" "set termoption dashed" – Sunil Verma Jan 14 '16 at 18:40
  • 1
    @SunilVerma - you have to remove the other `set term` and `set terminal` commands, or else, you will reset to `png` instead of `pngcairo` (hence the issue). Also, I think as of version 5, the `dashed` option for the terminal does not work anymore. – Schorsch Jan 14 '16 at 18:48
  • @Schorsch, awesome. Thanks a lot. yes, it worked like a charm. :-) I will update the new code as a reference to viewers. – Sunil Verma Jan 14 '16 at 18:59