You don't need any prior experience with Gnuplota or the terminal to read this manual, and you can use Windows. Instructions will guide you through Gnuplots from the beginning to more advanced fads. It is brief, but I recommend, in parallel with reading the commands, to try on your PC - the instructions are so written.

## What is Gnuplot?

Gnuplot also works as a terminal program on Linux. It is installed using a command, similar to sudo apt-get install gnuplot (by distra) and works just as it does on Windows.

## Fence command

Type the following code tentatively into the terminal and press enter:

Do you see that a window has appeared with a graph of the quadratic function $x^2$, which GnuPlot plotted on the graph something like this: You may notice several buttons on the top bar, the most important of which is the grid button with which you can load the grid (draw a square network in the chart). This can be replaced with a set grid command and turned off using the unset grid. With the second button from the left, you can save the chart as a picture. I won't describe the other buttons, you can try them yourself. So the fence command plots into the graph what we tell it, what we write next (or what's in the fence command argument). We can render the functions $\sin()$, $\cos()$, $\exp()$ etc., but remember that GnuPlot uses a decimal point (not a comma!) and the power is given not by a roof (^), but by a double multiplication (**). It is also possible to render multiple functions at once, separated by a comma, like this:

## To Edit a Chart

Sometimes the graph of the function we've drawn doesn't match our requirements. For example, the command-induced function plot sin(x)might not be as nicely displayed as we would like, plus the axis labels are missing and the legend is not pretty. Now let's see how we can change that.

• Using set ylabel \y\ and set xlabel \x\ we supply the axis labels.
• Using set title \Sinusoida\ we set the chart name.
• Using set xrange[0:6.5] we adjust the range of the $x$ axis.
• Using set xtics 0.5*3.14159 we set the $x$ axis to be numbered after half pi (pi rounding to $3.14159). • Finally, we can plot the graph and rename its legend with plot sin(x) title \y=sin(x)\. If you save these commands to your .gn file, then you can only load the commands with the load \path\k\file.gnu\ (or simply drag the file into the window and press enter). Note: in Gnuplot, you can move between directories of a classically Unix cd. Commands: Specifically, the following graph will emerge from these commands: Other commands I have not mentioned now, but might be useful: • set logscale x base → logarithmic scale • set format x \$10^{%L}$\ → logarithmic description of the x-axis • set format x \%.1f\ → one decimal place on the x axis • set key left (or right bottom top) → legend's position • unset key → disables the legend • help → help ## How to Plot Data You may want to bring your own data, perhaps from an experiment, into the graph. In this case, Gnuplot can help. You just have to create a file (ideally a .txt, I think you're also going to .csv) with the following dates: Data can be separated by both a tab and a space. The cross # indicates a comment, what's behind it is ignored by Gnuplot. Then plot \path\k\file.txt\ will bring up data. If you can't find a file path, drag the file to Gnuplot and rewrite the load to the fence of the command that will be created there. Test your data flow by trying to create the same chart as in one job from the correspondence seminar Exhaust. So let's get the data in the right format first (watch out, it has to have decimal dots): We then save the data to a file named data.txt (but it may be a different name) and then take it out using the plot \data.txt\. We then get this output: Note: I'm sure you learned in school that when plotting measured data into a chart, no matter what, you can't connect points - measured values. However, if you do want to do this, just type: plot \data.txt\ with lines for the path to the file in the plot command. ## How to Fit You're probably going to have some data plotted out at some point, and you're going to want to fit it, or fit it through a function. This too can be done in Gnuplot. Let's take a look at the data from last Exhaust Task. I will give here a step-by-step guide to how this is done: 1. First, you must estimate the shape of the function you want to interlace the chart. In this case, it's probably going to be a linear relationship, or$f(x) = a\cdot x+c$. 2. Let's define the function in gnuplot by typing its prescription into the terminal -- f(x) = a*x+c. 1. Note that the variable is$x$, but both$a$and$c$are parameters we don't know. 3. Now the program must calculate all the parameters. So write: 1. The program will list calculated fitness constants that may come in handy. 4. Finally, we plot both the function f(x) and the data in the graph as follows: This should be the chart: Of course, you can try to fit the data with other dependencies, but then when you command fit you have to specify all the parameters when via. You can find fitness insecurity in the program listing. Important: gnuplot fits does with its own numerical algorithm. This algorithm only works if they convert the values of the numbers. It doesn't need to be converted if you enter a parameter where just a small change results in a large change in function. Maybe if we have a f(x)=a*(1+x/b), then if b is small, this fit is unstable. Better use the equivalent fit in that case f(x)=a*(b+x). ## Other amenities of Gnuplot 1. You can also draw 3D charts. All you have to do is have a data set with three columns, or a two-variable function. The splot function takes care of that. Try entering the following line to see: 2. Errorbars can also be drawn. All you have to do is have a data file with three columns where the third column is the error bars in the$y\$ axis and write:
3. You can select a color and line type for the fenced data. To do this, read the documentation, the basic color change is made by the following command (lt means line type and colour is some predefined color):
4. set decimalsign ,
5. set encoding utf8 for Czech characters
6. set dt (number) changes dash type, which is good for black and white printing.
7. set key spacing 1.5magnifies the legend to make it more readable.

## How to write LaTeX axis labels

Gnuplot has various so-called terminals that indicate in which format the output will be. One is the LaTeX format, which comes in handy when you want Greek letters in the axis labels. It is used as follows:

This creates a sample.tex and sample.eps file in the folder where you are operating. Now in the terminal, you must compile the file using pdflatex sample.tex. But you can also compile from gnuplot using

Of course, the resulting sample.tex can be compiled in an editor, but it's more convenient through the terminal. I strongly recommend using load \plot.gnu\ for this type of compilation.

Did the Gnuplot story help? Perhaps my guide to LaTeX will help, or you can read one of my articles for example on foreign language learning or differential calculus.