Plotting and visualization tools: Difference between revisions

From Wiki Max
Jump to navigation Jump to search
Line 27: Line 27:
  gnuplot> plot "data.txt"  with linespoints # or "w lp" plot data points with lines
  gnuplot> plot "data.txt"  with linespoints # or "w lp" plot data points with lines
  gnuplot> plot "data.txt" w lp lc "blue"  ps 2 # with linespoint, color blue and larger point size
  gnuplot> plot "data.txt" w lp lc "blue"  ps 2 # with linespoint, color blue and larger point size
gnuplot> set xrange [0.2] #select a range for the x axis
gnuplot> replot
  gnuplot> plot "data.txt" u 2:3 t "data 2:3" w lp # we select column 2 and 3 and we add a legend
  gnuplot> plot "data.txt" u 2:3 t "data 2:3" w lp # we select column 2 and 3 and we add a legend
  gnuplot> !cat data.txt  #with ! we escape to shell and we can use all the shell command without exit from gnuplot
  gnuplot> !cat data.txt  #with ! we escape to shell and we can use all the shell command without exit from gnuplot
Line 34: Line 36:
  gnuplot> help plot # interactive help
  gnuplot> help plot # interactive help
  gnuplot> help plot style
  gnuplot> help plot style
[http://gnuplot.info http://gnuplot.info ] for Documentation and Demos
[http://gnuplotting.org http://gnuplotting.org] for more advanced scripting

Revision as of 11:01, 25 November 2020

Now we see some simple features of the software we will use to visualize and plotting data.

Gnuplot

Gnuplot is a powerful (and free!) program for plotting functions and data, also fit and interpolation can be done. Gnuplot allows realizing 1D and 2D plots, as well as contour plot and heatmaps. If you are using the QM virtual machine the software is already installed.

Let'start creating a data file with random numbers e.g.:

 $> cat > data.txt <<EOF 
 >0 2 4
 >1 5 3
 >2 4 2
 >3 6 4 
 EOF

and launch gnuplot by typing:

$>gnuplot

now we can plot functions by simply typing their expressions.

gnuplot> plot x**2.  # or just p x**2
gnuplot> plot x**2*sin(x)

or plot data contained in a file:

gnuplot> plot "data.txt"   # plot data points
gnuplot> plot "data.txt"  with linespoints # or "w lp" plot data points with lines
gnuplot> plot "data.txt" w lp lc "blue"  ps 2 # with linespoint, color blue and larger point size
gnuplot> set xrange [0.2] #select a range for the x axis
gnuplot> replot
gnuplot> plot "data.txt" u 2:3 t "data 2:3" w lp # we select column 2 and 3 and we add a legend
gnuplot> !cat data.txt  #with ! we escape to shell and we can use all the shell command without exit from gnuplot
gnuplot> save "myplot.gpt" #save the commands of your last plot into a file
gnuplot> load "myplot.gpt" #and load it
gnuplot> splot "data.txt" u 1:2:3 #2 dimensional plot
gnuplot> help plot # interactive help
gnuplot> help plot style

http://gnuplot.info for Documentation and Demos http://gnuplotting.org for more advanced scripting