Pgfplots:传递给原始 gnuplot 字符串无单位图宽度和高度

Pgfplots:传递给原始 gnuplot 字符串无单位图宽度和高度

梅威瑟:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots} 
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group size=1 by 4,
    vertical sep=0.1in,
  },
  scale only axis,
  width=\columnwidth-0.5in-0.09in,
  domain=-0.482362:0.035276,
  xmin=-0.495, xmax=0.0352762,
]
\nextgroupplot[
  height=0.8in,
  ymin=-0.9, ymax=4.9,
]
  \addplot
    gnuplot[id=plot1, raw gnuplot]
      {plot '< plotpointreduce -t 0.0175 --max-dist 0.1
         --width 2.897 --height 0.8
         --xrange \pgfkeysvalueof{/pgfplots/xmin} \pgfkeysvalueof{/pgfplots/xmax}
         --yrange \pgfkeysvalueof{/pgfplots/ymin} \pgfkeysvalueof{/pgfplots/ymax}
         --x-column delta --y-column v_12 data_fem_0.dat' u 'delta':'v_12'}
    ;
\end{groupplot}
\end{tikzpicture}
\end{document}

如何将groupplot和选项中轴宽度(\columnwidth-0.5in-0.09in)和高度(0.8in)的指定值传递给\nextgroupplot类似于--xrange和的原始 gnuplot 字符串--yrange原始 gnuplot 字符串?

脚本要求和plotpointreduce为无单位浮点数,仅考虑比率。--width--height

更新:

我把调用方式改为:

  \addplot
    gnuplot[id=plot1, raw gnuplot]
      {plot '< plotpointreduce -t 0.0175 --max-dist 0.1
         --width  \pgfkeysvalueof{/pgfplots/width}
         --height \pgfkeysvalueof{/pgfplots/height}
         --xrange \pgfkeysvalueof{/pgfplots/xmin} \pgfkeysvalueof{/pgfplots/xmax}
         --yrange \pgfkeysvalueof{/pgfplots/ymin} \pgfkeysvalueof{/pgfplots/ymax}
         --x-column delta --y-column v_12 data_fem_0.dat' u 'delta':'v_12'}
    ;

但是,\pgfkeysvalueof{/pgfplots/width}返回\columnwidth -0.5in-0.09in
我怎样才能将其转换为inch

我已经把冗长的“自制”脚本放在plotpointreduce放在https://gist.github.com/Hotschke/afdcd9efabe385c641a6

更新二

     --width  \the\pgfkeysvalueof{/pgfplots/width}

\the将扩大列宽。

我的脚本仍然抱怨plotpointreduce: error: argument -w/--width: invalid float value: '345.0pt-0.5in-0.09in'

所以我想我的问题只是扩展这个表达式。最短的方法是怎样的?

答案1

经过进一步的互联网搜索,我终于找到了答案。我不知道这是否是最可靠的方法:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepgfplotslibrary{groupplots} 
\makeatletter
\def\Printdimensionless#1{\strip@pt \dimexpr (#1)\relax}
\makeatother
% For convenience
\newcommand{\pwidth}{\Printdimensionless{\pgfkeysvalueof{/pgfplots/width}} } % trailing space important
\newcommand{\pheight}{\Printdimensionless{\pgfkeysvalueof{/pgfplots/height}} }
\newcommand{\pxrange}{\pgfkeysvalueof{/pgfplots/xmin} \pgfkeysvalueof{/pgfplots/xmax} }
\newcommand{\pyrange}{\pgfkeysvalueof{/pgfplots/ymin} \pgfkeysvalueof{/pgfplots/ymax} }
\begin{filecontents}{data_fem_0.dat}
id   delta      E_1        E_2        v_12       v_21       G_12     err         porosity  E_cs_1_norm  E_cs_2_norm
049  -0.48      2.6891     2.9098     0.33942    0.36728    1.1087   0.010752    0.914955  0.89481      0.968249
047  -0.46      0.014184   0.1251     -0.3269    -2.8832    0.71385  0.0011567   0.88558   0.00343525   0.0302982
\end{filecontents} % inserts '%' comment lines
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group size=1 by 2,
    vertical sep=0.1in,
  },
  scale only axis,
  width=\columnwidth-0.5in,
  domain=-0.482362:0.035276,
  xmin=-0.495, xmax=0.0352762,
]
\nextgroupplot[
  height=0.8in,
  ymin=-0.9, ymax=4.9,
]
  \addplot
    gnuplot[id=poisson12, raw gnuplot]
      {set datafile commentschars '#\%';
          \addplot
gnuplot[id=young1, raw gnuplot]
  {plot '< plotpointreduce -t 0.0
    --width  \pwidth --height \pheight
    --xrange \pxrange --yrange \pyrange
     -x delta -y E_cs_1_norm ./data_fem_0.dat' u 'delta':'v_12'}; 'delta':'v_12'}
    ;
\nextgroupplot[
  height=0.8in,
  ytick={0,0.5,1},
  ymin=0, ymax=1,
]
  \addplot
    gnuplot[id=young1, raw gnuplot]
      {set datafile commentschars '#\%';
        plot '< plotpointreduce -t 0.0
         --width  \pwidth --height \pheight
         --xrange \pxrange --yrange \pyrange
         -x delta -y E_cs_1_norm ./data_fem_0.dat' u 'delta':'E_cs_1_norm'};
\end{groupplot}
\end{tikzpicture}
\end{document}

有用的答案:

相关内容