gnuplot general
Installing gnuplot
apt-get install gnuplot apt-get install gnuplot-x11
Specify offset for axis labels
set xlabel "x" offset *,* set ylabel "y" offset *,*
Logarithmic scale setting and formatting of axis labels
set logscale x set format x "$10^{%L}$"
Set axis labels to display powers
set format x "$%.0t \\times 10^{%T}$"
Output in gnuplot epslatex
set terminal epslatex color 12(font size) set output "graph.eps"After drawing a graph, if you do not specify output as an alias immediately, the legend display of eps will be incorrect, or a compilation error will occur in the first place.
Creating a clean eps file with gnuplot's epslatex
If you just want to paste in LaTeX text, that's fine, but if you want to create a file with text in it\documentclass[12pt]{article} \usepackage[dvips]{graphicx} \pagestyle{empty} \begin{document} \input{graph.tex} \end{document}Compile the LaTeX file with the image pasted in with
dvips -E -o figure.eps figure.dviAs the margins are rather large as it is, minimize them using epstool (the standalone class is not so useful).
epstool --copy --bbox figure.eps dammy mv dammy figure.epsIf you script it for ubuntu, it looks like this
#!/bin/sh gnuplot $1.gp echo '\\documentclass[12pt]{article}' > figure.tex echo '\\usepackage[dvips]{graphicx}' >> figure.tex echo '\\usepackage{amsmath,amssymb}' >> figure.tex echo '\\pagestyle{empty}' >> figure.tex echo '\\begin{document}' >> figure.tex echo '\\input{graph.tex}' >> figure.tex echo '\\end{document}' >> figure.tex latex figure.tex dvips -E -o figure.eps figure.dvi epstool --copy --bbox figure.eps dammy mv dammy $1.eps rm graph.tex rm graph.eps rm figure*but at the beginning of gp file
set terminal epslatex color 12 set output "graph.tex"must be put. However, epstool can be buggy and produce a very strange BoundingBox (we have seen this happen when using set size square in combination with unset ytics).In this case, instead of using epstool, you can use
eps2eps figure.eps dammyand set the BoundingBox in dammy to the original figure.eps. If you want to make it a script
#!/bin/sh gnuplot $1.gp echo '\\documentclass[12pt]{article}' > figure.tex echo '\\usepackage[dvips]{graphicx}' >> figure.tex echo '\\usepackage{amsmath,amssymb}' >> figure.tex echo '\\pagestyle{empty}' >> figure.tex echo '\\begin{document}' >> figure.tex echo '\\input{graph.tex}' >> figure.tex echo '\\end{document}' >> figure.tex latex figure.tex dvips -E -o figure.eps figure.dvi eps2eps figure.eps dammy DAM=`sed -n '2,2p' dammy` sed -i "5c$DAM" figure.eps mv figure.eps $1.eps rm dammy rm graph.tex rm graph.eps rm figure*
Displaying graphs in ASCII art in gnuplot
set terminal dumb
How to use every in gnuplot
every line skip:block skip:initial line:initial block:end line:end block
plot a range
plot [a:b] f(x)is not very useful because it behaves strangely when it conflicts with set xrange. We can use the ternary operator something like that here
plot ((x-a)*(x-b) < 0 ? f(x) : 1/0)
Function plot with Mathematica-like appearance
See here (Jpn)Making histograms from list data only
I thought gnuplot would not make histograms from list data unlike paid graphing software such as Kaleida graph, but this was not the case. See here (Jpn)Combine multiple files into one plot
plot "< paste file1.dat file2.dat" using 1:($2/$4)
Drawing a line segment線分を引く
set arrow from *,* to *,* nohead lc * lw *
Draw a point
set label 1 point ps * pt * lc * at *,*When drawing a line or point with splot, also attach front.
Built-in function atan2(y,x)=atan(y/x)
Note that it is not atan2(x,y) (same as fortran, opposite to Mathematica)