Tuesday, July 19, 2005

Introduction to GnuPlot

from: http://learn.tsinghua.edu.cn/homepage/2001315450/gnuplot-doc/TOC.html

1, Variables and Functions

In 2D plots, the variable to use is x, in 3D plots, use x and y. Multiplication is denoted by *, and division by /. Exponents are denoted by**, and all multiplication must be explicit. That is, 3x would generate and error, you would want to use 3*x.

  • The standard trig functions, sin, cos, and tan Note, to use the constant pi can be referenced by just using pi.
  • The inverse trig functions , asin, acos, and atan.
  • The hyperbolic trig functions, sinh, cosh, and tanh.
  • The exp and log function. exp raises e to the power of its argument. For example, 4e2x would be 4*exp(2*x) in Gnuplot. log returns the natural log (base e) of it's argument. This corresponds to ln in normal math notation.
  • For information on other functions, type help functions in Gnuplot.
2, 2-D plot:
  • plot
To change the scale, use one of the following forms of plot:
  • plot [x1:x2] [y1:y2]
  • plot [x1:x2] (To just set the x range)
  • plot [] [y1:y2] (To just set the y range).
To set the default x range back to [-10,10], type the following:
  • set xrange [-10:10]
Also, if you set the range for the y values, they will stay the same for future plots as well. You can set GnuPlot back to autoscaling the y axis by typing the following:
  • set autoscale y
3, 3-D plot:
  • splot
  • splot [x1:x2] [y1:y2] [z1:z2]
  • splot [x1:x2] (To just set the x range)
  • splot [] [y1:y2] (To just set the y range).
  • splot [] [] [z1:z2] (To just set the y range).
hide the grid points on the drawing graph.
  • set hidden3d
  • replot
Increasing Precision of 3D plots
  • set isosamples x_rate, y_rate
Adding contour line
  • set contour base - Draw the contour lines along the base of the diagram
  • set contour surface - Draws the lines along the 3D surface
  • set contour both - Draws lines on both surface and base
  • set nocontour - Turns off contour lines
Changing view of graph
  • set view horizontal_angle,vertical_angle
  • set view horizontal_angle,vertical_angle,zoom
  • set view ,,zoom
4, Parametric Equations
  • set parametric
To go back to standard Cartesian mode, type:
  • set noparametric
To switch to graphing with polar coordinates, type:
  • set polar
To switch back to Cartesian coordinates, type:
  • set nopolar
Plotting Data
# Example1.dat
# number of subint. - width of subinterval, computed value, abs. error
0 1 5 0.00673794699908559

plot "example1.dat"

  • set logscale
  • set data style linespoints
  • replot
Change the plot's columns:
  • set nologscale
  • plot "example1.dat" using 1:3

3-D data plots:
  • set parametric
  • set data style lines
  • splot "try2.dat"
Outputs:
ps file:
  • set output "filename.ps" where filename.ps is the name of the output file.
  • set terminal postscript
  • replot
eps file:
  • set output "filename.eps"
  • set terminal postscript eps
Load from a file:
  • load 'work.gnu'
Line styles:
You can also add the with keywork to plot and splot commands. For example,
  • plot sin(x) with boxes
  • plot "turkey.dat" with impulses
The following line styles are available for 2D function and data plots: `lines`, `points`, `linespoints`, `impulses`, `dots`, `steps`, `errorbars`, `boxes`, and `boxerrorbars`

Define new variables and Functions:
  • constant_name = expression
  • function-name(parameters) = expression
Add time and title:
  • set time
  • set title "Farm Data Plot"
  • set nokey



0 Comments:

Post a Comment

<< Home