How To Plot 2Nd Information Using Gnuplot

As the publisher of this spider web site, I am interested inwards visualizing readership increase over time. With that inwards mind, I fix out to plot the issue of page views together with clicks over time.

Linux is good stocked amongst information plotting software. This 3-part serial introduces 2 explicate how to plot a points graph; business office 3, a bar chart.

Available to me is an input file containing, amid other things, the issue of page views together with ads clicks from 2005 to 2014.

 
Date Page views Clicks 2005-08-01 ix 0 2005-08-02 65 1 2005-08-03 twenty 0 <snipped> 2014-04-28 2811 8 2014-04-29 2862 10 2014-04-30 2256 2

To graph both page views together with clicks against time, the minimal gnuplot ascendancy sequence is equally follows:

 
fix lastly png fix output "webstats.png" plot "report.dat" using 1:2, \ "report.dat" using 1:3

The kickoff 2 commands specify respectively the output type (png format), together with the output filename (webstats.png).

The 3rd ascendancy specifies 2 plots amongst the same raw input information file(report.dat). The independent variable ("x") inwards both plots is the kickoff acre inwards the input file (the "1" inwards 1:2 together with 1:3). The subject variable ("y") is acre 2 together with acre iii respectively.

You tin run inwards each ascendancy interactively inwards gnuplot. Or seat all the commands inwards a script, nation mystats.gp, together with pipage the file to gnuplot.

 $ truthful cat mystats.gp |gnuplot 

The output graph plotted past times the higher upward commands is rather unreadable. The residuum of this post service explains how to plough that into this:

Below is the consummate script to generate the dainty looking graph. Please consult the official user manual for details.

 
# Plot fashion fix fashion information points # Term type & background color, canvass size fix lastly png background "#330000" size 1920, 960 \ font "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf,18" # Output file elevate fix output "webstats.png" # Input information configuration # fix datafile separator "," # fix datafile missing "?" # Independent variable (X) = Time serial fix xdata fourth dimension fix timefmt "%Y-%m-%d" fix format x "%Y/%m/%d" # Specify subset appointment hit xstart="2008-01-01" xend ="2014-06-01" fix xrange [xstart:xend] # Define custom display styles fix fashion job 1 lt 1 lc rgb "#FFCC66" fix fashion job 2 lt 2 lc rgb "#FF00FF" pt half dozen fix fashion job iii lc rgb "#FFFFFF" # Axis tic marks fix xtics textcolor linestyle iii rotate fix xtics xstart, 7776000, xend fix bmargin 8 fix ytics textcolor linestyle 1 fix y2tics textcolor linestyle 2 fix tics nomirror # Axis labels fix xlabel "Date" tc ls iii offset 0,-3 fix ylabel "Count" tc ls iii fix y2label "Count" tc ls iii # Key (Legend) fix cardinal font "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf,16" fix cardinal tc ls iii fix cardinal overstep left fix cardinal box ls iii lw 2 tiptop 2 spacing iii fix cardinal championship "Legend" fix cardinal Left # Misc. fix championship "Web Site Stats" tc ls iii fix grid fix edge linewidth 1 linestyle iii # Plot: Skip job 1 (heading) plot "report.dat" every ::1 using 1:2 \ championship "#PageViews" axes x1y1 ls 1, \ '' every ::1 using 1:3 \ championship "#Clicks" axes x1y2 ls 2

Plotting style

 fix fashion information [points| linespoints| lines] 

Specify the default plot style.

The points fashion draws a small-scale disjoint symbol for each "y" information value.

If you lot prefer side past times side symbols to live connected past times a line, purpose the linespoints style.

Want lines to connect the side past times side information values only no symbols? That is the lines style.

Terminal type

 
fix term png background "#330000" size 1920, 960 \ font "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf,18"

The set terminal ascendancy specifies the lastly type, the background color, the canvass size, together with the default text font.

  • Terminal type is a peculiar elevate to hateful the output format. Besides png, other notable types are pdf, jpeg, together with latex.
  • The default background color is white. If you lot desire a nighttime background, specify the color inwards the #RRGGBB format, for instance, #330000. On-line tools are available to assistance you lot position the color code.
  • The default canvass size is 640 x 480 pixels. The canvass is enlarged to concur all the required information.
  • The default font (Arial) together with font size (18) are specified.

Output filename

 fix output "webstats.png" 

Specify the output file inside quotes.

Input information configuration

fix datafile separator "," fix datafile missing "?"
  • By default, gnuplot assumes the fields inwards the input information are separated past times whitespaces (one or to a greater extent than spaces or tabs). If your input file is comma-separated, configure the separator parameter.
  • If your input file has missing data, fix the missing parameter to a particular string that denotes a acre does non accept a value, for instance, "?". Make certain that the empty fields inwards the input information file are populated amongst the "?" string.

Part 2 of this serial explains the residuum of the commands inwards the gnuplot script. Part 3 shows how to plot bar charts using gnuplot.

Berlangganan update artikel terbaru via email:

0 Response to "How To Plot 2Nd Information Using Gnuplot"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel