exercises:2015_uzh_molsim:gnuplot
Differences
This shows you the differences between two versions of the page.
— | exercises:2015_uzh_molsim:gnuplot [2020/08/21 10:15] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 2d plotting with Gnuplot ====== | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | Gnuplot is a powerful program that can be used to generate publication-quality figures. Here, we are going to introduce only a small subset of its features. If you are interested to learn more, have a look to the [[http:// | ||
+ | |||
+ | <note tip>You are free to choose a different plotting program for your analysis ([[http:// | ||
+ | |||
+ | '' | ||
+ | <code bash> | ||
+ | plot sin(x) | ||
+ | splot sin(x)*sin(y) | ||
+ | plot ' | ||
+ | replot ' | ||
+ | set xlabel "time steps" | ||
+ | set xrange [0:10] | ||
+ | replot | ||
+ | set terminal x11 enhanced font " | ||
+ | help < | ||
+ | exit # leave gnuplot (loosing unsaved graphs) | ||
+ | </ | ||
+ | |||
+ | Now you are ready to plot some actual data. | ||
+ | '' | ||
+ | |||
+ | < | ||
+ | |||
+ | - Open the file in a text editor. What quantities does it contain? | ||
+ | - Plot the kinetic energy and potential energy versus time. | ||
+ | - Add the sum of kinetic and potential energy to the plot. In which type of ensemble was this MD simulation performed? | ||
+ | - Label the axes of the plot with appropriate quantities and units. | ||
+ | |||
+ | </ | ||
+ | |||
+ | Later you will want to save your graphs in order to use them in your reports. This is done as follows: | ||
+ | <code bash> | ||
+ | set terminal png # we want to create a .png image | ||
+ | set output " | ||
+ | replot | ||
+ | set terminal x11 # switch back to plotting on screen | ||
+ | </ | ||
+ | |||
+ | |||
+ | Gnuplot is not just a plotting utility, it can also perform fits. | ||
+ | Say, we have a data set '' | ||
+ | We want to fit a function $f(x)=ax^2$ to this data set. In Gnuplot, this would be achieved by: | ||
+ | <code bash> | ||
+ | f(x) = a*x*x # Define function to be fitted | ||
+ | a = 1 # initial guess for a | ||
+ | fit f(x) " | ||
+ | </ | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | - Create a second plot, this time of temperature versus simulation time. | ||
+ | - Label axes of the plot with appropriate units. | ||
+ | - Use Gnuplot' | ||
+ | |||
+ | </ | ||
+ | |||
+ | 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 '' | ||
+ | <code bash> | ||
+ | gnuplot script.gp | ||
+ | gnuplot | ||
+ | load ' | ||
+ | </ | ||
+ | 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. | ||