6

I want to do multiplot or subplot in GNUplot. I have two files that has x1, y1 in two files. I want to have two graphs plotted in GNUplot like a subplot. Suppose I have the following two files

Plot1

12:14:38 10

12:15:38 11

12:16:38 12

12:17:38 15

and another file

Plot2

12:17:38 15

12:18:38 11

12:19:38 12

12:20:38 15

I want to generate two graphs for these two values. How do i do it using GNUplot. Can anyone please help me out.

Thanks

1 Answer 1

13

If I understand what you are asking, here is the basic syntax:

set term png size 600,400
set output 'plot.png'

set multiplot           # engage multiplot mode
set size 1.0,1.0        # sets the size of the first plot
set xdata time          ## these three lines control how gnuplot
set timefmt '%H:%M:%S'  ## reads and writes time-formatted data.
set format x '%H:%M:%S' ##

plot 'data1' u 1:2      # plot the first data set

set size 0.4,0.4        # set the size of the second plot in plot units
set origin 0.15,0.5     # set the origin for the second plot in plot units

plot 'data2' u 1:2      # plot the second data set

This will plot the second data set as a subfigure.

subfigure plot

To make two plots in a grid, you can use set multiplot layout:

set term png size 600,300
set output 'plot.png'

set multiplot layout 1,2        # engage multiplot mode
#set size 1.0,1.0       # sets the size of the first plot
set xdata time          ## these three lines control how gnuplot
set timefmt '%H:%M:%S'  ## reads and writes time-formatted data.
set format x '%H:%M:%S' ##
set xtics 120           # make time spacing of 2 minutes

plot 'data1' u 1:2      # plot the first data set 

#set size 0.4,0.4       # set the size of the second plot in plot units
#set origin 0.15,0.5    # set the origin for the second plot

plot 'data2' u 1:2      # plot the second data set 
unset multiplot

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

Hi .. I want two graphs in the same page. Not like the one which you showed. :(. Basically I want two or Four graphs in a single page. Can you please tell me how to do that.. Thanks a lot :)
@user1667228 -- that's because in gnuplot, its called multiplot. To create a "grid" of plots, you can just do set multiplot layout 2,2 (for a 2 by 2 grid). Of course, then you can tweak the position and size of each plot using origin and size like andyras did in this example, but that's rarely necessary.
Also, it's good practice to add an unset multiplot at the end ... I'm not sure if this is still the case, but some terminals used to wait for that before they wrote any data...
@mgilson is correct, it's fairly easy to make a grid of plots using multiplot layout x,y. Also in my script (I'm using 4.7) it plotted fine without unset multiplot, but I agree that is best practice, so I'll add it in.
@andyras -- Like I said, the behavior of your script if you don't have unset multiplot used to be terminal dependent, not (necessarily) gnuplot version dependent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.