Pgfplots:原始 gnuplot 设置数据文件注释字符‘#%’;如何转义‘%’?

Pgfplots:原始 gnuplot 设置数据文件注释字符‘#%’;如何转义‘%’?

平均能量损失

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepgfplotslibrary{groupplots} 
\makeatletter
\def\Printdimensionless#1{\strip@pt \dimexpr #1\relax}
\makeatother
\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 '#%'; # <-- SEE HERE
        plot './data_fem_0.dat' u '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 './data_fem_0.dat' u 'delta':'E_cs_1_norm'};
\end{groupplot}
\end{tikzpicture}
\end{document}

这将返回以下错误:

! Illegal parameter number in definition of \pgfplots@gnuplotcode.
<to be read again> 
                   p
l.33     ;

? 

查看 gnuplot 文件:

$ cat demo-expand-plot-width-expr.poisson12.gnuplot
set table "demo-expand-plot-width-expr.poisson12.table"; set format "%.5f"
set format "%.7e";;set datafile commentschars '##plot '< plotpointreduce -t 0.01 --width 308.865 --height 57.81621 --xrange -0.495 0.0352762 --yrange -0.9 4.9 --x-column delta --y-column v_12 data_fem_0.dat' u 'delta':'v_12'

显示设置 commentschars 不正确。显然必须%进行转义。\%很有用,但仍然会抛出错误。

$ cat demo-expand-plot-width-expr.poisson12.gnuplot
set table "demo-expand-plot-width-expr.poisson12.table"; set format "%.5f"
set format "%.7e";;set datafile commentschars '##\%'; plot './data_fem_0.dat' u 'delta':'v_12'

答案1

不确定结果是否符合预期,但这不会产生错误:

\begin{tikzpicture}
\makeatletter
\let\%\@percentchar
\edef\#{\string#}
\makeatother
\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 '\#\%';
        plot './data_fem_0.dat' u '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 './data_fem_0.dat' u 'delta':'E_cs_1_norm'};
\end{groupplot}
\end{tikzpicture}

在此处输入图片描述

答案2

这不是一个真正的答案,但却是解决问题的一种可能方法。

datafile commentschars在 gnuplot 配置文件中调整。

  1. $HOME/.gnuplot(全球的)
  2. $PWD/.gnuplot(每个目录)(需要编译时选项+USE_CWDRC 可以通过运行来验证$ gnuplot -e "show version long; show loadpath"

相关内容