
점 (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}