我正在尝试添加经过点 (1000,-8.5) 和 (10000,-27.79) 的线。这是我目前拥有的乳胶。
\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xmode=log,
xlabel={Frequency (Hz)},
ylabel={Gain (db)},
xmin=0, xmax=20000,
ymin=-30, ymax=10,
xtick={0,100,1000,10000},
ytick={10,0,-10,-20,-30},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,
mark=square,
only marks,
]
coordinates {
(100,-0.18)(1000,-8.5)(2000,-14.15)(4000,-19.83)(10000,-27.79)
};
% add plot of equation going through points (1000,-8.5) and (10000,-27.79) here
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
所有经过这两个点的方程式都无法正确显示在图中,我猜是因为对数刻度。我试过 49.37-19.29*x,但不起作用。该方程式是在计算连接两点的线之前应用 log(x) 得出的。我如何得到一条经过这些点的线?
答案1
怎么样
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmode=log,
xlabel={Frequency (Hz)},
ylabel={Gain (db)},
xmin=0, xmax=20000,
ymin=-30, ymax=10,
xtick={0,100,1000,10000},
ytick={10,0,-10,-20,-30},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
legend pos=north east
]
\addplot[
color=blue,
mark=square,
only marks,
]
coordinates {
(100,-0.18)(1000,-8.5)(2000,-14.15)(4000,-19.83)(10000,-27.79)
};
\addlegendentry{data}
\addplot[color=orange,no marks] coordinates {(1000,-8.5) (10000,-27.79)};
\addlegendentry{fit}
\end{axis}
\end{tikzpicture}
\end{document}