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}

相關內容