Gnuplot Explained (Part 2/3)

Part 1 of this series presented a gnuplot script to plot the next two-dimensional graph. This postal service continues the give-and-take of the commands inwards the script.

Time serial variable

gear upward xdata fourth dimension gear upward timefmt "%Y-%m-%d" gear upward format x "%Y/%m/%d"
  • The get-go ascendance - set xdata time - explicitly tells gnuplot that the "x" variable contains timestamps.
  • The 2nd ascendance specifies how those timestamps are formatted inwards the input information file. For a listing of timestamp element codes, delight refer to the Time/date specifiers department (page 114) inwards the official gnuplot manual.
  • The 3rd ascendance - set format x - specifies the format of tic labels on the "x" axis.

Narrow appointment range

xstart="2008-01-01" xend ="2014-06-01" gear upward xrange [xstart:xend]
  • The raw input information file contains information from 2005 to 2014, a bridge of close ix years. You tin flame plot a subset of the information past times specifying a narrower appointment range.
  • The to a higher house representative defines 2 user variables - xstart in addition to xend - to delimit the "x" appointment attain for the plot. Later, nosotros reuse the variables to specify the appointment attain for the tic marks on the "x" axis.

Custom draw of piece of occupation styles

gear upward mode draw of piece of occupation 1 lt 1 lc rgb "#FFCC66" gear upward mode draw of piece of occupation 2 lt 2 lc rgb "#FF00FF" pt half-dozen gear upward mode draw of piece of occupation three lc rgb "#FFFFFF"
  • The lines in addition to request symbols inwards a plot receive got default properties such equally color, in addition to shape. The to a higher house commands define custom styles which tin flame last assigned to a plot element to override the default belongings values.
  • Line styles 1, 2, in addition to three are created.
  • As defined, draw of piece of occupation styles 1 in addition to 2 are based on the default draw of piece of occupation types (lt) of the same number. H5N1 novel draw of piece of occupation color(lc) is specified for the 2 draw of piece of occupation styles.
  • For draw of piece of occupation mode 2, the request type (pt) is besides changed. The request type defines the shape of the request symbol: type half-dozen is a modest circle.

To persuasion the default draw of piece of occupation type properties, executing the next gnuplot commands, in addition to examine the output png:

gear upward in conclusion png gear upward output 'test.png' examine gear upward output

Axis tic marks

gear upward xtics textcolor linestyle three rotate gear upward ytics textcolor linestyle 1 gear upward y2tics textcolor linestyle 2 gear upward xtics xstart, 7776000, xend gear upward bmargin 8 gear upward tics nomirror
  • The tic marks on the "x" axis (xtics) adopt the text color of draw of piece of occupation mode three defined earlier. Similarly, the tic marks for the "y" in addition to "y2" axes adopt the text color of draw of piece of occupation styles 1 in addition to 2, respectively. Note that "y2" is the vertical axis on the correct mitt side.

    The color alter is necessary because the default color for tic marks assumes a white background. Given that the background was modified to a nighttime color, the tic marks blend into the background, making them invisible without the change.

  • By default, all axes are auto-scaled. The script specifies explicitly the scale for the "x" axis inwards the course of teaching of a triplet: xstart, 7776000, xend. The 2 user-defined variables, xstart in addition to xend, comprise the 2nd in addition to the max tic score values on the "x" axis, respectively. The catch number is the increment inwards seconds (7776000 seconds equal xc days).
  • Normally, the labels on the "x" axis are written horizontally. Using the horizontal orientation results inwards labels overlapping each other. To solve this problem, the script rotates the "x" axis labels past times xc degrees, thus rendering them vertically.

    H5N1 side outcome is that the bottom margin (bmargin) needs to last increased to compensate for the longer "x" axis labels.

  • By default, all tic marks are mirrored on the contrary edge (left "y" axis to correct in addition to vice versa, in addition to bottom "x" axis to hand in addition to vice versa). The set tics nomirror ascendance configures tic marks to non mirror.

Axis labels

gear upward xlabel "Date" tc ls three offset 0,-3 gear upward ylabel "Count" tc ls three gear upward y2label "Count" tc ls three
  • The axis labels are assigned the text color(tc) of draw of piece of occupation mode (ls) 3. Note that yous tin flame abbreviate the names of mutual gnuplot objects: ls for linestyle.
  • The color alter is necessary to brand the labels visible inwards a nighttime background.
  • The "x" label is relocated downward past times the offset to compensate for the vertical labels.

Key/Legend

gear upward telephone commutation championship "Legend" gear upward telephone commutation font "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf,16" gear upward telephone commutation textcolor ls three gear upward telephone commutation box ls three lw 2 pinnacle 2 spacing three gear upward telephone commutation hand left gear upward telephone commutation Left
  • The set telephone commutation box ascendance specifies that the legend is to last enclosed inwards a box.

    The box is assigned draw of piece of occupation mode 3. The draw of piece of occupation width(lw), the height, in addition to the spacing are customized to become inwards await pretty.

  • By default, the legend is placed at the hand correct corner within the plot. The set telephone commutation hand left ascendance relocates the legend to the hand left.
  • The Left keyword (with the working capital missive of the alphabet L) left justifies the text inwards the legend body.

Miscellaneous

gear upward championship "Web Site Stats" textcolor ls three gear upward grid gear upward edge linewidth 1 linestyle three
  • H5N1 championship for the plot is specified, in addition to assigned the text color of draw of piece of occupation mode 3.
  • Grid lines are enabled.
  • Borders are enabled, in addition to assigned a draw of piece of occupation width in addition to style.

Plot

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

With the set-up complete, nosotros are produce to number the plot command.

  • Two plots are defined, separated past times a comma on the ascendance line.
  • Both plots are taken from the same input information file: report.dat.

    As a shorthand, movement into 2 quotes for the 2nd plot instead of repeating the filename.

  • every ::1 skips the get-go draw of piece of occupation inwards the input file which is the heading line. Instead, nosotros specify explicitly the titles on the plot ascendance line.
  • The origin of the variables "x" in addition to "y" are specified past times the 2 numbers inwards using x:y. The variable "x" inwards both plots is taken from the get-go plain inwards the input file (the "1" inwards 1:2 in addition to 1:3). The variable "y" is taken from plain 2, in addition to plain three respectively.
  • The 2 plots part the same x1 axis (the bottom axis). The number of page views are placed on the y1 (left) axis acre the clicks are placed on the y2 (right) axis.
  • The 2 plots are assigned the draw of piece of occupation styles (ls) 1 in addition to 2 respectively.

Part three of the serial illustrates how to plot a bar nautical chart using gnuplot.

Berlangganan update artikel terbaru via email:

0 Response to "Gnuplot Explained (Part 2/3)"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel