Pages

Wednesday, February 1, 2012

2D Basics: functions and data plotting

When you start to get interested with a concrete software (let me say some fancy words here... you bastard!) you don't give a shit about all the details but yet, all the pages you search are full of... say details you don't give a damn about.

What I'm saying its that "I better prefer to explore than decode". I don't want to study. I want to get to the point I'm searching.

To plot a function you just define it and it will show to you. Go to the console, write gnuplot and do

[...]
f(x,a,b) = a*x**2 + b 
plot f(x,10,30) title 'the simplest plot'
[...]

you will get this


to change the format style (color, line type: doted, dashed, lines-points) do

[...]
plot f(x,10,30) with linespoints pointsize 0.5 pointtype 2 linecolor rgb "black" title 'f(x,a,b) with lines and points'
[...]


Change the parameters as you wish to get another stuff.

  • Tables

Now we will generate a table of $x$-$y$ data and plot it as it was a data file we had for something else


[...]
## Using functions to generate data : tables
set output 'f(x,a,b).table'
set table
plot f(x,10,30)
unset table
reset # If you don't reset you will print the results on 'f(x,a,b).table'

## Ploting data from a file

plot 'f(x,a,b).table' using 1:2 t 'Plotting from a file'
[...]

You get the same you got but as it was data


  • Parametric plots
You need to make a grid (there are another ways, but that will be shared later). A grid is just a table of $x$-$y$ points. Your computer always discretizes the space in order to evaluate the function you with to it. In 2D the grid is just a straight line. So we do, 

[...]
set xrange [0:2*pi] # Yes, pi is defined within gnuplot, awesome ha? No less that one should expect!
set yrange [-1:1] 

set output 'xy-grid.table' # This is the output file to use later
set table
plot x 
unset table
reset # If you don't reset you will print the results on 'xy-grid.table'

plot 'xy-grid.table' using 1:2 title "The grid is a line if you are not a curved space dealer"
[...]

Which looks like

Now we use the file "xy-grid.table" to plot whatever function we want using explicit parameterization
of the axes.We will use the axes

[...]
set size square # This sets the scale of 'x' the same as 'y' 1 to 1 proportion

plot 'xy-grid.table' using ( cos($2) ):( sin($2) ) title 'this was a fucking line!!', \
     'xy-grid.table' using ( cos($2)/5 ):( sin($2)/5 ) title 'this was another fucking line!!'
[...]
I plotted two "different" parametrizations, so you can see how its done.

That's all!
Bye

No comments:

Post a Comment