# Given a user-provided data file of values of a function z on a mesh # in the x,y-plane, this script draws contour lines of z(x,y) in the # x,y-plane. # The name of the data file should be as specified on the splot # command below. # Assuming that the x and y positions are equally spaced, the data # file can just have the mesh z-values, one per line, with the # x-coordinate varying fastest, and a blank line between lines of # different y. In that case, the plotted x and y-values are integer, # and full xtics and ytics will need to be specified. # Otherwise you need to specify all three of x, y, and z in the data # file, one set of three numbers on each line. You should have y # going fastest, and blank lines in between lines of different x. # In Fortran terms, if i is the index in the x-direction, j the one in # the y-direction, and z(i,j) are the function values for which to # plot contour lines, the data file could be created as: # 10 format(3g15.5) # do 30 i=1,imax # do 20 j=1,jmax # write(1,10)x(i),y(j),z(i,j) # 20 continue # write(1,10) # 30 continue # Substitute your favorite equivalent C, C++, or m code as desired. # Numbers should normally be separated by blank space, not commas. If # you have an existing data file that uses commas, like an excel file, # set the data file separator below. # Normally, you can run this script from a terminal as # gnuplot contour.txt # In case of problems, check the error messages by using # gnuplot # load "contour.txt" # File cmmi10.pfa should be in the current folder. # Start of the script commands. # Lines starting with '# ' are comments that are ignored. Lines # starting with '#' not followed by a space are disabled commands. # You can enable such a command by removing the # # First let gnuplot put the contours in a plot file called contour_tmp.plt. # let output go to the file set table 'contour_tmp.plt' # specify contour lines to be drawn in the base xy-plane set contour base # do not draw a surface f(x,y), just contour lines unset surface # plot everything at this stage set xrange [:] set yrange [:] set zrange [:] # connect the found points on the contours by straight lines set cntrparam linear # draw contours for about 10 levels of z, with automatically selected z values set cntrparam levels auto 10 # or draw contours for exactly the given z values #set cntrparam levels discrete -.4, -.2, 0, .2, .4, .6, .8, 1. # or draw contours for the shown start value, increment, and end value #set cntrparam levels incremental -2, 0.5, 2 # if the data are separated by commas, uncomment the line below (remove #) #set datafile separator "," # now plot the contour lines of the z-values in the user's data file splot "goertler.plt" # finish unset table # Next plot contour_tmp.plt as a 2D data set. # set terminal to postscript (plot size is 5 by 3 inches) set terminal postscript eps size 5, 3 enhanced \ fontfile "cmmi10.pfa" "Times-Roman" 20 # output file name of the plot set output 'contour.eps' # size of the major and minor tick marks set tics scale 0.5, 0.25 # x plot range as [BEGIN:END] (use [:] to plot all x) set xrange [:] # x-axis label (see ps_guide.pdf for details) set xlabel '{/CMMI10 x}' offset 0, 0 # user-specified labels and corresponding tick positions #set xtics ("0" 0, "1" 1, "2" 2) # do not copy the ticks to the top boundary of the graph set xtics nomirror # y plot range as [BEGIN:END] (use [:] to plot all y) set yrange [:] # y-axis label (see ps_guide.pdf for details) set ylabel '{/CMMI10 y}' offset 0, 0 # user-specified labels and corresponding tick positions #set ytics ("0" 0, "0.5" .5, "1.0" 1) # do not copy the ticks to the right boundary of the graph set ytics nomirror # right-hand axis plot range as [BEGIN:END] (use [:] to plot all y2) #set y2range [:] # right hand axis label (see ps_guide.pdf for details) #set y2label '{/CMMI10 y_{/Times-Roman=15 2}}' offset 0, 0 # turn on tick marks on the right-hand y-axis #set y2tics # put labels inside the graph (see ps_guide.pdf for details) #set label '{/Times-Roman White Miata Goertler Vortices}' at screen .33, 0.9 # plot curves of type lt and thickness width lw (in pt); plot "contour_tmp.plt" axes x1y1 notitle with lines lt 1 lw 1 \ #, "points.plt" axes x1y1 notitle with points pt 6 ps 0.6 \ #, "curves.plt" axes x1y2 notitle with lines lt 4 lw 1 \ # the above lines that are commented out show how you could add # symbols of type pt and size ps, and/or curves using the right-hand # y-axis. See ps_symbols.pdf for details on symbols and line types. # end