TikZ 中的错误函数图

TikZ 中的错误函数图

我正在处理多项式函数,但 TikZ 图与 Excel 的输出不一致。我该如何解决这个问题?

代码(该代码由 GeoGebra 生成):

\documentclass[a4paper,12pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}

\begin{document}
\definecolor{wqwqwq}{rgb}{0.3764705882352941,0.3764705882352941,0.3764705882352941}
 \definecolor{ffffqq}{rgb}{1.,1.,0.}
\definecolor{ffzzqq}{rgb}{1.,0.6,0.}
\definecolor{wwccqq}{rgb}{0.4,0.8,0.}
\definecolor{qqzzqq}{rgb}{0.,0.6,0.}
\definecolor{qqzzff}{rgb}{0.,0.6,1.}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\definecolor{ffqqqq}{rgb}{1.,0.,0.}
\definecolor{ffdxqq}{rgb}{1.,0.8431372549019608,0.}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.45cm,y=5.3cm, scale=0.8]
\draw[->,color=black] (0.,0.) -- (24.,0.);
\foreach \x in {,4, 8, 12, 16, 20}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt); 
\node[below] at (4,0) {\footnotesize 1000};
\node[below] at (8,0) {\footnotesize 1004};
\node[below] at (12,0) {\footnotesize 1008};
\node[below] at (16,0) {\footnotesize 1012};
\node[below] at (20,0) {\footnotesize 1016};
\draw[->,color=black] (0.,0.) -- (0.,1.1);
\foreach \y in {,0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\clip(0.,0.) rectangle (24.,1.1);
\draw[line width=1.2pt,color=qqzzff,smooth,samples=100,domain=0.0:24.0] plot(\x,{4.244791666606611E-4*(\x)^(3.0)-0.015178571428663822*(\x)^(2.0)+0.1307440476188998*(\x)+0.2656000000143808});
\draw[line width=1.2pt,color=wwccqq,smooth,samples=100,domain=0.0:24.0] plot(\x,{1.3802083330884915E-4*(\x)^(3.0)-0.005848214285732765*(\x)^(2.0)+0.07114880952747568*(\x)+0.3771999998698159});
\draw[line width=1.2pt,color=ffffqq,smooth,samples=100,domain=0.0:24.0] plot(\x,{6E-5*(\x)^(3.0)-0.0023*(\x)^(2.0)+0.0284*(\x)+0.3408});
\begin{scriptsize}
\draw [fill=qqqqff] (4.,0.571) circle (2.5pt);
\draw [fill=qqqqff] (8.,0.565) circle (2.5pt);
\draw [fill=qqqqff] (12.,0.371) circle (2.5pt);
\draw [fill=qqqqff] (16.,0.218) circle (2.5pt);
\draw [fill=qqqqff] (20.,0.203) circle (2.5pt);
\draw[color=qqzzff] (-1.46,-0.65); 
\node [color=qqzzff, right] at (0,0.95) {$y_1= 0.0004x^3 - 1.2835x^2 + 1293.6x -434593$};
\draw [fill=qqzzqq] (4.,0.576) circle (2.5pt);
\draw [fill=qqzzqq] (8.,0.647) circle (2.5pt);
\draw [fill=qqzzqq] (12.,0.621) circle (2.5pt);
\draw [fill=qqzzqq] (16.,0.588) circle (2.5pt);
\draw [fill=qqzzqq] (20.,0.564) circle (2.5pt);
\draw[color=wwccqq] (-1.46,-0.11); 
\node [color=wwccqq, right] at (0,0.85) {$y_2 = 0.0001x^3 - 0.4183x^2 + 422.48x - 142243$};
\draw [fill=ffzzqq] (4.,0.42) circle (2.5pt);
\draw [fill=ffzzqq] (8.,0.452) circle (2.5pt);
\draw [fill=ffzzqq] (12.,0.44) circle (2.5pt);
\draw [fill=ffzzqq] (16.,0.436) circle (2.5pt);
\draw [fill=ffzzqq] (20.,0.431) circle (2.5pt);
\draw[color=ffffqq] (-1.46,0.11); 
\node [color=ffdxqq, right] at (0,0.75) {\tiny{$y_3 = 5.599\times 10^{-5}x^3 - 0.1696x^2 + 171.26x -57640 $}};
\node [left] at (0, 1.1) {$S_{t}$};
\draw [color=ffqqqq] (9, 0.659)-- ++(-2.0pt,-2.0pt) -- ++(4.0pt,4.0pt) ++(-4.0pt,0) -- ++(4.0pt,-4.0pt);
\node [color=ffqqqq, right] at (9, 0.659) {$(1005, 0.659)$};
\draw [color=ffqqqq] (6, 0.584)-- ++(-2.0pt,-2.0pt) -- ++(4.0pt,4.0pt) ++(-4.0pt,0) -- ++(4.0pt,-4.0pt);
\node [color=ffqqqq, right] at (6, 0.584) {$(1002, 0.584)$};
\end{scriptsize} 
\end{tikzpicture} \\
(b) Sea level pressure (hPa) criteria. 
\end{document}

来自 Excel 的绘图: 在此处输入图片描述

TikZ 输出 在此处输入图片描述

非常感谢!

答案1

如果您使用 pgfplots,则图形是相同的。

\documentclass{standalone}
%
\usepackage{tikz}
\usepackage{pgfplots}
  \pgfplotsset{compat=1.13}

\begin{document}

\begin{tikzpicture}
\begin{axis} [ width=12cm,
    xlabel = $x$, ylabel = $y$,
    domain = 5:20, no marks, ymin=0
    ]
\addplot{4.244791666606611E-4*(x)^(3.0)-0.015178571428663822*(x)^(2.0)+
         0.1307440476188998*(\x)+0.2656000000143808};
\addplot{1.3802083330884915E-4*(x)^(3.0)-0.005848214285732765*(x)^(2.0)+
         0.07114880952747568*(x)+0.3771999998698159};
\addplot{6E-5*(x)^(3.0)-0.0023*(x)^(2.0)+0.0284*(x)+0.3408};
\end{axis}  
\end{tikzpicture}

\end{document}

图表:

在此处输入图片描述

相关内容