将gnuplot与latex相结合:方法和输出

san*_*arp 1 latex gnuplot

我正在运行以下脚本:

#!/bin/bash
gnuplot -e "set t latex ; set size 0.5,1; set output 'grafico.tex';
 set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2); set xrange [-pi/2:pi/2]; 
 set yrange [-2:2]; set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x); pause -1 'hit return to continue'"
pdflatex latex
atril latex.pdf
Run Code Online (Sandbox Code Playgroud)

输出1

产量

作为编程和gnuplot的初学者,我想确保这是正确的方法.我的怀疑来自输出,它看起来不太好(主要是分辨率).我有什么简单的改进吗?任何改进以改善绘图技术和提高结果都将受到欢迎.


输出2

更改latexcairolatex pdf作为建议@Ethan梅里特的回报:

OUT2

这要好得多.

Eth*_*han 7

gnuplot的原始乳胶终端,你说的"定期乳胶",现代标准是可怕的.使用最近的一个.我最喜欢的是tikz终端:

gnuplot的>

set term tikz standalone size 5cm, 7cm
set output 'grafico.tex'
set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2)
set xrange [-pi/2:pi/2]; set yrange [-2:2];
set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x)
unset output
system("pdflatex grafico")
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 您应该将大小设置为set term命令的一部分.如果使用set size您的输出将包含大的空白区域

  • 您的本地gnuplot副本可能不支持tikz终端.在这种情况下,你可以使用set term cairolatex pdf,其他一切都相同.

  • gnuplot还有其他(太多!)基于乳胶的终端,但我建议从tikz或cairolatex开始.