gnuplot epslatex unable to get replot

馋奶兔 提交于 2019-12-11 06:33:38

问题


When I use replot in the epslatex terminal, anything I replot is not showing up in the final output.

reset session
set terminal epslatex size 5.0in,4in color colortext font ',10' standalone

set output 'plots.tex'

set size square

plot sin(x)
replot cos(x)

set output

When I use , and plot in the same line, I get correct outputs.

reset session
set terminal epslatex size 5.0in,4in color colortext font ',10' standalone

set output 'plots.tex'

set size square

plot sin(x), cos(x)

set output

replot is very convenient becuase I can use set and change settings.

My question is how to use replot in gnuplot that prints in LaTeX.


回答1:


In gnuplot both commands are different. Using plot sin(x) followed by replot cos(x) draws two plots: one with sin(x) and another one with the result of the previous plot command (ie sin(x)) and cos(x). Indeed

plot sin(x)
replot cos(x)

is absolutely equivalent to

plot sin(x)
plot sin(x), cos(x)

If you display the 'plots-inc.eps' or if you change the terminal to pdf, you have two pages, the first with the plot of sin(x) and the second with both.

The plots.tex file is supposed to be included in a some tex source and only contains one plot. The actual function that is plotted in the .tex file is the last one (with sin(x) and cos(x)). This code is adapted to dvi output and if you format it with latex plots.tex (and not pdflatex plots.tex) and view the .dvi file with xdvi (or whatever), you can verify that a plot with both functions is present. For unknown reasons, with pdflatex, only the sin(x) appears (but both are in the .tex code and there is the legend for cos(x)).

Here is what I get in the .dvi file:

We can do a zoom on this dvi file.

And compare it to the second plot if we use a pdf terminal.

As you can see, the plot rendering is worse with the dvi file and the function is smoother with the pdf output.

I think the problem is that the epslatex terminal is a very old driver. It was the default in the nineties, but with modern TeX engines, almost no one uses it anymore and I am not sure that it is actively maintained.

This probably explains the problems : the incomplete plot with pdflatex and the lower quality of the rendering. Most probably this driver has never really been adapted to engines like pdflatex or lualatex.

Unless you absolutely need dvi, I would suggest you to switch to another driver. Generate your plots as pdf and use \includegraphics to load them. The plot quality will be increased, but you will also gain all the flexibility of \includegraphics to resize, rotate, clip or do whatever you want to your plots.

Please note that the pdf driver will generate one plot per page and with your initial code there are two plots. You can include a specific page (ie plot) of the pdf with the 'page=' option of \includegraphics, but the simpler is to select different output files per plot.

set output 'plots.pdf'
plot sin(x)
set output 'plots2.pdf'
replot cos(x)


来源:https://stackoverflow.com/questions/57138312/gnuplot-epslatex-unable-to-get-replot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!