epslatex gnuplot图的水平放置

时间:2014-07-22 20:21:59

标签: gnuplot pdflatex

我用gnuplot生成一个带有以下代码的图:

  set logscale y
  set xlabel "iteration"
  set ylabel "$\\varepsilon$"
  set terminal epslatex color  size 3.5,3.5
  set out 'l2_errors_with_iteration_cc=00001_dt=1200_test.tex'
  plot  "l2_errors_with_iteration_cc=.00001_damping=0.9_dt=0.1200.txt" using 1:2 title 'current' with lines lw 4
  set out
  quit

包含以下数据:

 0   2.03616944439
 0   2.03616944439
 2   0.25330118741
 3   0.22665346605
 4   0.20262719150
 5   0.18101252740
 6   0.16160551934
 7   0.14420900466
 8   0.12863525831
 9   0.11470804565
10   0.10226380345
11   0.09115208853
12   0.08123549251
13   0.07238919637
14   0.06450029952
15   0.05746702167
16   0.05119784692
17   0.04561065697
18   0.04063188453
19   0.03619570607
20   0.03224328518
21   0.02872207183
22   0.02558515939
23   0.02279069871
24   0.02030136683
25   0.01808388719
26   0.01610859780
27   0.01434906324
28   0.01278172704
29   0.01138560027
30   0.01014198331
31   0.00903421712
32   0.00804746131
33   0.00716849603
34   0.00638554533
35   0.00568811962
36   0.00506687532
37   0.00451348969
38   0.00402054934
39   0.00358145092
40   0.00319031255
41   0.00284189508
42   0.00253153177
43   0.00225506578
44   0.00200879445
45   0.00178941964
46   0.00159400355
47   0.00141992933
48   0.00126486603
49   0.00112673731
50   0.00100369368
51   0.00089408768
52   0.00079645182
53   0.00070947891
54   0.00063200454
55   0.00056299152
56   0.00050151594
57   0.00044675483
58   0.00039797511
59   0.00035452379
60   0.00031581922
61   0.00028134330
62   0.00025063454
63   0.00022328189
64   0.00019891921
65   0.00017722041
66   0.00015789505
67   0.00014068445
68   0.00012535825
69   0.00011171132
70   0.00009956099
71   0.00008874462
72   0.00007911742
73   0.00007055053
74   0.00006292926
75   0.00005615155
76   0.00005012662
77   0.00004477376
78   0.00004002118
79   0.00003580510
80   0.00003206884
81   0.00002876204
82   0.00002583994
83   0.00002326277
84   0.00002099512
85   0.00001900543
86   0.00001726544
87   0.00001574978
88   0.00001443551
89   0.00001330171
90   0.00001232920
91   0.00001150022
92   0.00001079827
93   0.00001020797
94   0.00000971499
95   0.00000930611
96   0.00000896921
97   0.00000869333
98   0.00000846870
99   0.00000828674
100   0.00000814002
101   0.00000802220
102   0.00000792792
103   0.00000785271
104   0.00000779289
105   0.00000774543
106   0.00000770786
107   0.00000767818
108   0.00000765479
109   0.00000763639
110   0.00000762194
111   0.00000761064
112   0.00000760180
113   0.00000759492
114   0.00000758957
115   0.00000758544
116   0.00000758225
117   0.00000757980

借助以下tex文件生成一个非常好的情节:

% GNUPLOT: LaTeX picture with Postscript
\begingroup
  \makeatletter
  \providecommand\color[2][]{%
    \GenericError{(gnuplot) \space\space\space\@spaces}{%
      Package color not loaded in conjunction with
      terminal option `colourtext'%
    }{See the gnuplot documentation for explanation.%
    }{Either use 'blacktext' in gnuplot or load the package
      color.sty in LaTeX.}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\includegraphics[2][]{%
    \GenericError{(gnuplot) \space\space\space\@spaces}{%
      Package graphicx or graphics not loaded%
    }{See the gnuplot documentation for explanation.%
    }{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
    \renewcommand\includegraphics[2][]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \@ifundefined{ifGPcolor}{%
    \newif\ifGPcolor
    \GPcolortrue
  }{}%
  \@ifundefined{ifGPblacktext}{%
    \newif\ifGPblacktext
    \GPblacktexttrue
  }{}%
  % define a \g@addto@macro without @ in the name:
  \let\gplgaddtomacro\g@addto@macro
  % define empty templates for all commands taking text:
  \gdef\gplbacktext{}%
  \gdef\gplfronttext{}%
  \makeatother
  \ifGPblacktext
    % no textcolor at all
    \def\colorrgb#1{}%
    \def\colorgray#1{}%
  \else
    % gray or color?
    \ifGPcolor
      \def\colorrgb#1{\color[rgb]{#1}}%
      \def\colorgray#1{\color[gray]{#1}}%
      \expandafter\def\csname LTw\endcsname{\color{white}}%
      \expandafter\def\csname LTb\endcsname{\color{black}}%
      \expandafter\def\csname LTa\endcsname{\color{black}}%
      \expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
      \expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
      \expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
      \expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
      \expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
      \expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
      \expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
      \expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
      \expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
    \else
      % gray
      \def\colorrgb#1{\color{black}}%
      \def\colorgray#1{\color[gray]{#1}}%
      \expandafter\def\csname LTw\endcsname{\color{white}}%
      \expandafter\def\csname LTb\endcsname{\color{black}}%
      \expandafter\def\csname LTa\endcsname{\color{black}}%
      \expandafter\def\csname LT0\endcsname{\color{black}}%
      \expandafter\def\csname LT1\endcsname{\color{black}}%
      \expandafter\def\csname LT2\endcsname{\color{black}}%
      \expandafter\def\csname LT3\endcsname{\color{black}}%
      \expandafter\def\csname LT4\endcsname{\color{black}}%
      \expandafter\def\csname LT5\endcsname{\color{black}}%
      \expandafter\def\csname LT6\endcsname{\color{black}}%
      \expandafter\def\csname LT7\endcsname{\color{black}}%
      \expandafter\def\csname LT8\endcsname{\color{black}}%
    \fi
  \fi
  \setlength{\unitlength}{0.0500bp}%
  \begin{picture}(5040.00,5040.00)%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%
      \put(1342,704){\makebox(0,0)[r]{\strut{} 1e-06}}%
      \put(1342,1286){\makebox(0,0)[r]{\strut{} 1e-05}}%
      \put(1342,1867){\makebox(0,0)[r]{\strut{} 0.0001}}%
      \put(1342,2449){\makebox(0,0)[r]{\strut{} 0.001}}%
      \put(1342,3030){\makebox(0,0)[r]{\strut{} 0.01}}%
      \put(1342,3612){\makebox(0,0)[r]{\strut{} 0.1}}%
      \put(1342,4193){\makebox(0,0)[r]{\strut{} 1}}%
      \put(1342,4775){\makebox(0,0)[r]{\strut{} 10}}%
      \put(1474,484){\makebox(0,0){\strut{} 0}}%
      \put(2002,484){\makebox(0,0){\strut{} 20}}%
      \put(2530,484){\makebox(0,0){\strut{} 40}}%
      \put(3059,484){\makebox(0,0){\strut{} 60}}%
      \put(3587,484){\makebox(0,0){\strut{} 80}}%
      \put(4115,484){\makebox(0,0){\strut{} 100}}%
      \put(4643,484){\makebox(0,0){\strut{} 120}}%
      \put(176,2739){\rotatebox{-270}{\makebox(0,0){\strut{}$\varepsilon$}}}%
      \put(3058,154){\makebox(0,0){\strut{}iteration}}%
    }%
    \gplgaddtomacro\gplfronttext{%
      \csname LTb\endcsname%
      \put(3656,4602){\makebox(0,0)[r]{\strut{}current}}%
    }%
    \gplbacktext
    \put(0,0){\includegraphics{l2_errors_with_iteration_cc=00001_dt=1200_test.pdf}}%
    \gplfronttext
  \end{picture}%
\endgroup

使用以下代码生成我的文档:

\documentclass[aps,showpacs,twocolumn,10pt,pra]{revtex4-1}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{float}
\begin{document}
\section{Introduction} \label{sec:Introduction}
\blindtext
\blindtext
\blindtext

\begin{figure}[H]
\centering
\input{l2_errors_with_iteration_cc=00001_dt=1200_test.tex}
\caption{Here we see the error plotted as a function of iteration.}%
\end{figure}

\end{document}

现在,问题。在上面的代码中,我可以更改此行:

 \begin{picture}(5040.00,5040.00)%

更具体地说是第一个数字,使其变大或变小。将其缩小会使得到的数字向右移动。因此,将其放大应该将图形向左移动。但事实并非如此。为什么?我想这样做是因为我认为情节的左边有太多的空间,ylabel似乎很孤独。我可以通过改变这一行来移动它:

  \put(176,2739){\rotatebox{-270}{\makebox(0,0){\strut{}$\varepsilon$}}}%

将176增加(或减少)到我想要的任何值,但这并没有改变这样的事实,即似乎有比所需要的更多的空间。有趣的是,增加或减少第二个5040.00-实际上可以根据需要向上或向下移动图表(据我测试过),这就是为什么我觉得这可能是一个错误。

1 个答案:

答案 0 :(得分:1)

通过复制你的数字,我发现左边的空格太多是由于\varepsilon文件中的y标签gnuplot

我可以通过用gnuplot命令

来抵消y标签来重现一个好位置的数字
set ylabel offset 3,0 "$\\varepsilon$"

gnuplot文件中。您无需在begin{picture}环境中更改定位。