【问题标题】:horizontal placement of epslatex gnuplot figureepslatex gnuplot 图的水平放置
【发布时间】:2014-07-23 08:42:07
【问题描述】:

我使用 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 -does- 实际上将情节向上或向下移动到一个喜欢的程度(据我测试过),这就是为什么我觉得这可能是一个错误。

【问题讨论】:

  • 对于大型抽动格式也会发生同样的情况,请参见例如stackoverflow.com/a/20522516/2604213。 Gnuplot 无法正确确定 LaTeX 格式的标签位置和边距。
  • 你能分享set terminal epslatex这一行吗?
  • 不知道你的意思..我包括了这一行set terminal epslatex color size 3.5,3.5

标签: gnuplot pdflatex


【解决方案1】:

通过复制您的图,我看到左侧太多的空白是由于 gnuplot 文件中的 y 标签 \varepsilon

我可以通过使用gnuplot 命令偏移 y 标签来重现一个放置良好的图形

set ylabel offset 3,0 "$\\varepsilon$"

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

【讨论】:

  • 这会将ylabel 向右移动,但不会消除空白问题。设置边距,例如set lmargin at screen 0.1,应该有助于填充 gnuplot 画布上的空白区域(在此示例中为 3.5 英寸宽)。
  • 太棒了。 Madhurjya 的回答和 Miguel 的建议都导致了可接受的解决方案。但是,set lmargin at screen 0.1 还需要在 tex 文件中重新定位 varepsilon(可能还有其他方法可以做到这一点(它被设置为 -290)),所以 Madhurjya 的答案似乎需要更少的工作。谢谢!
  • @juggler 您必须结合两个答案。更改 ylabel 偏移量和左边距。您应该避免更改 TeX 文件本身的任何内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
  • 2012-11-09
  • 1970-01-01
相关资源
最近更新 更多