我正在尝试用以下代码分散小而相似的数据:
\begin{tikzpicture}
\begin{axis}[
xlabel={\(\displaystyle (\Delta t)^4\)},
xmajorgrids,
xmin=-4.96554799726869e-06, xmax=0.000104998359428441,
ylabel={\(\displaystyle z\)},
ymajorgrids,
ymin=-120.776647344602, ymax=-120.776636703454,
]
\addplot [semithick]
table {%
0.0001 -120.776646860914
4.82253086419753e-05 -120.776641857922
2.32568039361378e-05 -120.776639434005
1.12156654784615e-05 -120.776638270216
5.40878929323954e-06 -120.776637707272
2.60840533045889e-06 -120.776637436398
1.25791152124753e-06 -120.77663730572
6.0663171356459e-07 -120.776637242653
2.92550016186627e-07 -120.776637212275
1.4108314823815e-07 -120.77663719762
6.80377836796633e-08 -120.776637190555
3.28114311726771e-08 -120.776637187143
};
\addlegendentry{RK4}
\end{axis}
\end{tikzpicture}
预期结果(使用 绘制matplotlib
)是:
但是,LaTeX 输出是:
问题在于 y 值非常小并且彼此相似。
我尝试手动缩放 y 数据,但这只会使比例变大,而不会显示线性趋势。使用scaled y axis ticks=true
科学计数法强制重新缩放也不起作用。
答案1
有一种似乎可行的办法,就是使用xfp
,它可以更好地处理这些数字,重新调整绘图的值,并以另一种方式缩放刻度标签。
\documentclass{article}
\usepackage{pgfplots}
\usepackage{xfp}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={\(\displaystyle (\Delta t)^4\)},
xmajorgrids,
xmin=-4.96554799726869e-06, xmax=0.000104998359428441,
ylabel={\(\displaystyle z\)},
ymajorgrids,
%ymin=-120.776647344602, ymax=-120.776636703454,
yticklabel={\pgfmathprintnumber[precision=6,fixed zerofill]{\fpeval{\tick/1e6-120.7766}}}
]
\addplot [semithick]
table [x=x,y expr={\fpeval{(\thisrow{y}+120.7766)*1e6}}] {%
x y
0.0001 -120.776646860914
4.82253086419753e-05 -120.776641857922
2.32568039361378e-05 -120.776639434005
1.12156654784615e-05 -120.776638270216
5.40878929323954e-06 -120.776637707272
2.60840533045889e-06 -120.776637436398
1.25791152124753e-06 -120.77663730572
6.0663171356459e-07 -120.776637242653
2.92550016186627e-07 -120.776637212275
1.4108314823815e-07 -120.77663719762
6.80377836796633e-08 -120.776637190555
3.28114311726771e-08 -120.776637187143
};
\addlegendentry{RK4}
\end{axis}
\end{tikzpicture}
\end{document}