Vector
Main

Out of the Box

Gnuplot is extremely powerful, but can be difficult to learn, especially as there are no tutorials worthy of the name. This is planned to be a brief introduction, mostly for mathematical graphing. Gnuplot has wide applications, from financial, to map-making, to art. Specifics of these other applications are not included here, but I hope enough of the basics will be covered to make demos from other fields easier to understand and adapt.

Windows Operating System

These remarks are about Gnuplot 5.0 in Windows. There are almost certainly better ways to do many things with Gnuplot in Unix-like systems (Linux, BSD, Cygwin, OSx, etc.). Gnuplot is not a part of the GNU software project (applications for Unix-like systems). The name is just coincidental.

There are two configuration files for gnuplot which, judging from questions on various forums, are frequently confused or not found at all. There are also a few other settings you probably want to change for convenience. The installation is somewhat backwards because things you are unlikely to want change are easy to change and things you are most likely to want to change are difficult to find.

This assumes you are the primary user on a Windows 7 PC or laptop and you have administrator powers. If this is not the case, this How-To may help clarify some issues so you know what to ask the administrator for.

It also assumes you have done a default installation of gunplot 5.0 and everything is where the installer put it if you did not alter any options in the installation.

Decide on a directory (folder)

You can run gnuplot wherever you want, but it is convenient to have a directory (folder) to keep your plots, images, and gnuplot scripts. This will reduce the typing of pathnames. When you have decided on a folder or created one, right click any shortcut icon you may have, choose Properties, and enter the path to your gnuplot folder in the "Start in" box.

Now when you open gunplot, you should see the path to your folder when you enter pwd (present working directory) at the gnuplot prompt. You can change directories (folders) from the gnuplot prompt or you can output and load from any other directory by using a pathname with the respective commands. This is just a convenience so that most of the time you do not need to change directories or type pathnames.

gnuplot.ini

The file gnuplot.ini only affects the placement, size, and font of the command window. It does not affect plots in any way. There is no reason to edit it directly. Even if you put plot options in it, they will be ignored. Set the command window in the position and size you want it to default to when you open it. Use the "Options" dropdown from the toolbar to change font if you wish and to wrap long lines or not, then click the "Update" option in the "Options" menu. You do not get any feedback on this operation, but the next time you pen gnuplot the command window should be just like it was when you updated from the "Options" menu. The file gnuplot.ini maybe located in C:\Users\<your user name>\AppData\Roaming, but the Options drop down will give the correct location.

gnuplotrc

The file you probably do want to edit is gnuplotrc.

In Unix-like systems, gnuplotrc is supposed to be merely a model (template) which is copied to the user's home directory, so customizations in it only affect gnuplot when run by that particular user. I have not been able to discover how to make this work in Windows 7.

The system-wide gnuplotrc is in the program files. This may be in C:\Program Files (x86)\gnuplot\share. As installed this file contains commented out lines to serve as models. Gnuplot will work fine without changing this file at all, so it may be best to leave it alone until you are experienced enough to make useful changes.

This is where you put gnuplot command you want to be executed whenever you start gnuplot. Typically linetypes would be defined in gnuplotrc unless you are really happy with the default colors. All gnuplotrc entries can be unset or set to different values. If you have made changes to gnuplotrc values, reset session will restore the original values from gnuplotrc.

Kick the tires

Open gnuplot. Gnuplot is basically a command-line program, so you should get a terminal-like screen with some lines of information and the gnuplot prompt gnuplot>. When you plot, plots will open in another window.

Out of the box, gnuplot has some workable, if not very attractive, defaults, so enter plot sin(x) at the prompt to see what you have got.

Plot window

This should open a plot window with a reasonable, but not necessarily attractive sine curve. Making pretty is most of the work in gnuplot, and creating configurations that can be saved for prettifying will save much work in the long run.

In the meantime, click the little cross hairs anywhere in the plot window and type h so that a list of plot-window hot keys will be listed in the command-line window. Worth looking at in the plot window are 7 which rotates through several scales, g which turns grid lines off and on, and r which turns measuring from the cross hairs to another point on and off. Notice that the position of the cross hairs cursor, in the scale of the plot is given in the lower left of the plot window, even when the cursor is outside the border of the plot.

Plot expressions

Out of the box, the plot command understands expressions in x. The 3D splot command understands expressions in x and y.

Expressions are not equations. Eventually you can define your own functions and variables, but until you have, gnuplot expects expressions in the independent variable x (and y for splot). This is why the first plot above was sin(x), not y=sin(x).

Gnuplot expressions are FORTRAN-like, but if you do not know FORTRAN there are only a few adjustments you need to make from the usual keyboard notations used in many calculators.

  • Exponents are entered with ** (double asterisks) not the caret (^).
  • Gnuplot does not recognize e as the base of natural logarithms. It uses the function exp() instead, where the exponent part goes in the parenthesis. To obtain the value of ''e', just use exp(1).
  • Multiplication is indicated with * (single asterisk). It is best always to enter it explicitly.
  • You can use the Functions drop-down menu to enter the common functions that gnuplot knows although most of them are what you would expect and you can just type them out.

Several expressions can be entered at the same time by separating them with commas. Try: splot sin(x),cos(y) and plot sin(x),cos(x). If you enter expressions with widely different ranges, the autoscaling may products (unpleasantly) surprising results: for example plot sin(x),exp(x). (Fixes for this will be discussed.)

Reset Command

Gnuplot will remember settings throughout a session (but loses them when you close gnuplot and restart). When you get really odd results and suspect the problem may be a setting you have changed, you can make gnuplot return to the defaults with the command reset.

Unfortunately, this will also wipe out setting that you do want, which is why it is a good idea to make and use configuration files for common groups of settings.

A few settings are not affected by reset. Examples are linetype and loadpath. To restore these as if you had closed and reopened gnuplot, use reset session.

Command Line

As with many terminals, you can bring previous commands to the prompt with the up arrow key. You can edit the command before you press enter. You can also use the Prev button in the tool bar. If you pass the previous command you want, you can use the down arrow on the keyboard or the Next button to go the other way through the list of previous commands. Gnuplot will remember the list of previous commands (but will not enact them) even after reset or closing gnuplot.

The drop-down menus can help you learn and remember commands, but if there is any chance you will use gnuplot on other platforms, it is good to learn to enter the commands with the keyboard.


<< Gnuplot Tutorial Trail | Gnuplot Tutorial Trail | More Basics >>

Sources:

gnuplot 4.2 Copyright (C) 1986 - 1993, 1998, 2004, 2007 Thomas Williams, Colin Kelley
Permission to use, copy, and distribute this software and its documentation for any purpose with or without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation.

Recommended:

Categories:


edit

This is a student's notebook. I am not responsible if you copy it for homework, and it turns out to be wrong.

Backlinks

This page is GnuplotTutorial1