
ポイント (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}
これら 2 つの点を通るすべての方程式がプロットに正しく表示されません。対数スケールが原因だと思います。49.37-19.29*x を試してみましたが、うまくいきませんでした。この方程式は、2 つの点を結ぶ線を計算する前に 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}