Pgfplots 和 pgfmathparse,缺乏精度

Pgfplots 和 pgfmathparse,缺乏精度

我正在使用 pgfplots 绘制图形,我想在绘制数据时修改横坐标值。我目前使用它x filter/.code={\pgfmathparse{1/#1} \pgfmathresult}来取 x 值的倒数。但是,对于这个数学运算,似乎缺乏精度。以下是 MWE,其中的输出不是所需的:

\documentclass[a4paper]{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
width=10cm,
height=5cm,
]
\addplot [x filter/.code={\pgfmathparse{1/#1} \pgfmathresult}]
  table[row sep=crcr]{%
665.123474243553    50.0709210000000\\ 
665.124802332690    49.6678125000000\\ 
665.126130403923    49.7686245000000\\ 
665.127458480460    49.7501640000000\\ 
665.128786585510    49.6496310000000\\ 
665.130114672653    49.8061035000000\\ 
665.131442788313    50.1225825000000\\ 
665.132770886063    49.5357525000000\\ 
665.134099012330    49.4506110000000\\ 
665.135427120687    50.0079600000000\\ 
665.136755257560    49.0017465000000\\ 
665.138083376527    49.5523995000000\\ 
665.139411524010    49.7646720000000\\ 
665.140739653583    49.7826210000000\\ 
665.142067788460    49.3249215000000\\ 
665.143395951857    48.9346470000000\\ 
665.144724097340    48.6674580000000\\ 
665.146052271343    48.2280330000000\\ 
665.147380427437    46.8564690000000\\ 
665.148708612050    46.2079800000000\\ 
665.150036778750    44.7215610000000\\ 
665.151364973970    44.2429365000000\\ 
665.152693151283    43.3782690000000\\ 
665.154021357110    44.1923910000000\\ 
665.155349545030    44.8409730000000\\ 
665.156677761467    45.3737235000000\\ 
665.158005959997    46.7979255000000\\ 
665.159334163827    47.2520910000000\\ 
665.160662396177    48.7288845000000\\ 
665.161990610620    48.5122410000000\\ 
665.163318853580    49.2502890000000\\ 
665.164647078630    48.5547885000000\\ 
665.165975332200    49.2531720000000\\ 
665.167303567860    50.3161155000000\\ 
665.168631832037    49.4624685000000\\ 
665.169960078307    49.6258695000000\\ 
665.171288353093    50.0582730000000\\ 
665.172616609973    49.7700195000000\\ 
665.173944872157    49.7608590000000\\ 
665.175273162857    49.8229830000000\\ 
665.176601435650    49.8743190000000\\ 
665.177929736963    49.8491160000000\\
};

\end{axis}
\end{tikzpicture}
\end{document}

有没有什么办法可以提高精度呢?

编辑解决方案:

\documentclass[a4paper]{article}
\usepackage{pgfplots,xfp}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
width=10cm,
height=5cm,
xticklabel style={/pgf/number format/fixed,/pgf/number format/precision=6, rotate=45}
]
\addplot [x filter/.code={\def\pgfmathresult{\fpeval{1/#1}}}]
  table[row sep=crcr]{%
665.123474243553    50.0709210000000\\ 
665.124802332690    49.6678125000000\\ 
665.126130403923    49.7686245000000\\ 
665.127458480460    49.7501640000000\\ 
665.128786585510    49.6496310000000\\ 
665.130114672653    49.8061035000000\\ 
665.131442788313    50.1225825000000\\ 
665.132770886063    49.5357525000000\\ 
665.134099012330    49.4506110000000\\ 
665.135427120687    50.0079600000000\\ 
665.136755257560    49.0017465000000\\ 
665.138083376527    49.5523995000000\\ 
665.139411524010    49.7646720000000\\ 
665.140739653583    49.7826210000000\\ 
665.142067788460    49.3249215000000\\ 
665.143395951857    48.9346470000000\\ 
665.144724097340    48.6674580000000\\ 
665.146052271343    48.2280330000000\\ 
665.147380427437    46.8564690000000\\ 
665.148708612050    46.2079800000000\\ 
665.150036778750    44.7215610000000\\ 
665.151364973970    44.2429365000000\\ 
665.152693151283    43.3782690000000\\ 
665.154021357110    44.1923910000000\\ 
665.155349545030    44.8409730000000\\ 
665.156677761467    45.3737235000000\\ 
665.158005959997    46.7979255000000\\ 
665.159334163827    47.2520910000000\\ 
665.160662396177    48.7288845000000\\ 
665.161990610620    48.5122410000000\\ 
665.163318853580    49.2502890000000\\ 
665.164647078630    48.5547885000000\\ 
665.165975332200    49.2531720000000\\ 
665.167303567860    50.3161155000000\\ 
665.168631832037    49.4624685000000\\ 
665.169960078307    49.6258695000000\\ 
665.171288353093    50.0582730000000\\ 
665.172616609973    49.7700195000000\\ 
665.173944872157    49.7608590000000\\ 
665.175273162857    49.8229830000000\\ 
665.176601435650    49.8743190000000\\ 
665.177929736963    49.8491160000000\\
};

\end{axis}
\end{tikzpicture}
\end{document}

答案1

使用 xfp 我得到了这个

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{pgfplots,xfp}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
width=10cm,
height=5cm,
]
\addplot [x filter/.code={\fpeval{1/#1}}]
  table[row sep=crcr]{%
665.123474243553    50.0709210000000\\
665.124802332690    49.6678125000000\\
665.126130403923    49.7686245000000\\
665.127458480460    49.7501640000000\\
665.128786585510    49.6496310000000\\
665.130114672653    49.8061035000000\\
665.131442788313    50.1225825000000\\
665.132770886063    49.5357525000000\\
665.134099012330    49.4506110000000\\
665.135427120687    50.0079600000000\\
665.136755257560    49.0017465000000\\
665.138083376527    49.5523995000000\\
665.139411524010    49.7646720000000\\
665.140739653583    49.7826210000000\\
665.142067788460    49.3249215000000\\
665.143395951857    48.9346470000000\\
665.144724097340    48.6674580000000\\
665.146052271343    48.2280330000000\\
665.147380427437    46.8564690000000\\
665.148708612050    46.2079800000000\\
665.150036778750    44.7215610000000\\
665.151364973970    44.2429365000000\\
665.152693151283    43.3782690000000\\
665.154021357110    44.1923910000000\\
665.155349545030    44.8409730000000\\
665.156677761467    45.3737235000000\\
665.158005959997    46.7979255000000\\
665.159334163827    47.2520910000000\\
665.160662396177    48.7288845000000\\
665.161990610620    48.5122410000000\\
665.163318853580    49.2502890000000\\
665.164647078630    48.5547885000000\\
665.165975332200    49.2531720000000\\
665.167303567860    50.3161155000000\\
665.168631832037    49.4624685000000\\
665.169960078307    49.6258695000000\\
665.171288353093    50.0582730000000\\
665.172616609973    49.7700195000000\\
665.173944872157    49.7608590000000\\
665.175273162857    49.8229830000000\\
665.176601435650    49.8743190000000\\
665.177929736963    49.8491160000000\\
};

\end{axis}
\end{tikzpicture}
\end{document}

相关内容