User Tools

Site Tools


exercises:2014_uzh_molsim:gnuplot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
exercise:mm_uzh:gnuplot [2014/04/24 16:39] talirzexercises:2014_uzh_molsim:gnuplot [2020/08/21 10:15] (current) – external edit 127.0.0.1
Line 7: Line 7:
 <note tip>You are free to choose a different plotting program for your analysis ([[http://matplotlib.org/|matplotlib]] might e.g. be an interesting alternative). However, Gnuplot is very versatile, can get the job done quickly and is still used by many computational scientists today.</note> <note tip>You are free to choose a different plotting program for your analysis ([[http://matplotlib.org/|matplotlib]] might e.g. be an interesting alternative). However, Gnuplot is very versatile, can get the job done quickly and is still used by many computational scientists today.</note>
  
-''gnuplot'' starts interactive Gnuplot console+''gnuplot'' starts the interactive Gnuplot console. This are some of the commands we are going to need:
 <code bash> <code bash>
 plot sin(x)                                # use plot for 2d plots plot sin(x)                                # use plot for 2d plots
 splot sin(x)*sin(y)                        # use splot for 3d plots splot sin(x)*sin(y)                        # use splot for 3d plots
-plot 'spectrum.energ' using 1:4            # plot column 1 as x and column 4 as y+plot 'spectrum.ener' using 1:4            # plot column 1 as x and column 4 as y
 replot 'spectrum.ener' using 1:($3+$5) title 'Total energy' replot 'spectrum.ener' using 1:($3+$5) title 'Total energy'
-set ylabel "time steps"+set xlabel "time steps"
 set xrange [0:10] set xrange [0:10]
 replot                                     # redo the plot with current settings replot                                     # redo the plot with current settings
Line 33: Line 33:
 </note> </note>
  
-Now we need to save the graph in order to be able to use . This is done as follows+Later you will want to save your graphs in order to use them in your reports. This is done as follows:
 <code bash> <code bash>
 set terminal png              # we want to create a .png image set terminal png              # we want to create a .png image
Line 42: Line 42:
  
  
-Finally, we want to use Gnuplot's fitting functionality.+Gnuplot is not just a plotting utility, it can also perform fits.
 Say, we have a data set ''data.dat'', which contains $x$ in the first column and some computed $f(x)$ in the second column. Say, we have a data set ''data.dat'', which contains $x$ in the first column and some computed $f(x)$ in the second column.
-We want to fit a function $f(x)=ax^2$ to this data set. Then we do:+We want to fit a function $f(x)=ax^2$ to this data set. In Gnuplot, this would be achieved by:
 <code bash> <code bash>
 f(x) = a*x*x                   # Define function to be fitted f(x) = a*x*x                   # Define function to be fitted
Line 54: Line 54:
 <note>**TASK 2** <note>**TASK 2**
  
-  - Create a second plot, this time of temperature versus time.+  - Create a second plot, this time of temperature versus simulation time.
   - Label axes of the plot with appropriate units.   - Label axes of the plot with appropriate units.
   - Use Gnuplot's fitting functionality to extract the //average// temperature.   - Use Gnuplot's fitting functionality to extract the //average// temperature.
Line 60: Line 60:
 </note> </note>
  
 +Finally, once you have figured out which commands you need to create the plot you want, it is a good idea to write these commands to a file, say ''script.gp''. This has the advantage that gnuplot can re-create your graph in an instant. On the bash terminal type:
 +<code bash>
 +gnuplot script.gp   # let gnuplot perform the commands in 'script.gp'
 +gnuplot             # alternative: start gnuplot
 +load 'script.gp'    #              and load script from within gnuplot
 +</code>
 +This makes it very quick and easy to change details in the plot at a later point in time.
 +Proficient gnuplot users will often start by writing the file, run it through gnuplot and then adjust the remaining details.
  
exercises/2014_uzh_molsim/gnuplot.1398357561.txt.gz · Last modified: 2020/08/21 10:14 (external edit)