更新:我意识到了我的问题。
我需要绘制一条对数回归线。我试图绘制下面的线性回归线。我该怎么做?
我找到了这篇讨论该主题的旧帖子,但我真的不明白这个答案到底在说什么。似乎有一个与(2012 年 11 月 27 日星期二上午 10:30)发布的帖子相关的 .dat 文件。这篇文章还展示了输入函数然后自动填充趋势线的能力。
https://latex.org/forum/viewtopic.php?t=22000
\documentclass[12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage{indentfirst}
\usepackage{subcaption}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{float}
\renewcommand{\baselinestretch}{1}
\usepackage{booktabs,caption}
\usepackage{tikz}
\usepackage{scalerel}
\usepackage{pict2e}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\usetikzlibrary{patterns,arrows.meta}
\usetikzlibrary{shadows}
\usetikzlibrary{external}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{statistics}
\usepgfplotslibrary{fillbetween}
\usepackage[flushleft]{threeparttable}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmode=normal,
ymode=normal,
log ticks with fixed point,
%axis lines=center,
grid=both,
scale only axis=true,
%ymin=0, ymax=.0025,
%xmin=0, xmax=1,
%xtick distance=2,
legend pos=outer north east,
clip mode=individual,
%axis lines=middle,
title=Second Circuit DC Mode(Normal Graph),
ylabel=Voltage\,(V),
xlabel=Time\,(S),
%scaled ticks=true,
%enlargelimits=0.2,
%x axis line style={shorten >=-35pt, shorten <=-35pt},
%x label style={xshift=35pt},
%y axis line style={shorten >=0pt, shorten <=-35pt},
%y label style={yshift=-5pt},
]
\addplot[opacity=.7,
only marks,
mark=triangle*,
red
]
table {
x y
0 10
30 7.42
60 5.57
90 4.25
120 3.25
150 2.49
180 1.92
210 1.47
240 1.14
270 0.895
300 0.696
330 0.552
360 0.433
390 0.342
420 0.276
450 0.221
480 0.181
510 0.149
540 0.124
570 0.104
600 0.089
};
\addplot [opacity=.5] table[
y={create col/linear regression={y=Y}}] % compute a linear regression from the input table
{
X Y
0 5.599164502
30 5.237209957
60 4.875255411
90 4.513300866
120 4.15134632
150 3.789391775
180 3.427437229
210 3.065482684
240 2.703528139
270 2.341573593
300 1.979619048
330 1.617664502
360 1.255709957
390 0.893755411
420 0.531800866
450 0.16984632
480 -0.192108225
510 -0.554062771
540 -0.916017316
570 -1.277971861
600 -1.639926407
};
\end{axis}
\end{tikzpicture}
\vfill
\begin{tikzpicture}
\begin{semilogyaxis}[
xlabel=Time(S),ylabel=Voltage(V),scale only axis=true, grid=both,clip mode=individual,title=Second Circuit DC Mode(Log),]
\addplot[color=blue, only marks,
mark=triangle*,
red] coordinates {
(0, 10)
(30, 7.42)
(60, 5.57)
(90, 4.25)
(120, 3.25)
(150, 2.49)
(180, 1.92)
(210, 1.47)
(240, 1.14)
(270, 0.895)
(300, 0.696)
(330, 0.552)
(360, 0.433)
(390, 0.342)
(420, 0.276)
(450, 0.221)
(480, 0.181)
(510, 0.149)
(540, 0.124)
(570, 0.104)
(600, 0.089)
};
\addplot [opacity=.5] table[
y={create col/linear regression={y=Y, ymode=log}}}}] % compute a linear regression from the input table
{
X Y
0 5.599164502
30 5.237209957
60 4.875255411
90 4.513300866
120 4.15134632
150 3.789391775
180 3.427437229
210 3.065482684
240 2.703528139
270 2.341573593
300 1.979619048
330 1.617664502
360 1.255709957
390 0.893755411
420 0.531800866
450 0.16984632
480 -0.192108225
510 -0.554062771
540 -0.916017316
570 -1.277971861
600 -1.639926407
};
\end{semilogyaxis}
\end{tikzpicture}
\end{document}
更新日期 2022.02.27
\documentclass[12pt,twoside]{report}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}[scale=1.2]
\begin{axis}[
xmode=normal,
ymode=log,
xlabel=Time(S),ylabel=Voltage(V),scale only axis=true, grid=both,clip mode=individual,title=Second Circuit DC Mode(Log),]
\addplot[color=blue, only marks,
mark=triangle*,
red] table{
X Y
0 10
30 7.42
60 5.57
90 4.25
120 3.25
150 2.49
180 1.92
210 1.47
240 1.14
270 0.895
300 0.696
330 0.552
360 0.433
390 0.342
420 0.276
450 0.221
480 0.181
510 0.149
540 0.124
570 0.104
600 0.089
};
\addplot [opacity=.5] table[
y={create col/linear regression={y=Y, ymode=log}}] % compute a linear regression from the input table
{
X Y
0 5.599164502
30 5.237209957
60 4.875255411
90 4.513300866
120 4.15134632
150 3.789391775
180 3.427437229
210 3.065482684
240 2.703528139
270 2.341573593
300 1.979619048
330 1.617664502
360 1.255709957
390 0.893755411
420 0.531800866
450 0.16984632
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
(我甚至不确定这是否是你想要的,所以如果不是,对于误解感到抱歉,我会删除答案。)
如果我添加ymode=log
回归选项,即\addplot [opacity=.5] table[y={create col/linear regression={y=Y, ymode=log}}]
,并从坐标列表中删除负输入值,我会得到以下结果:
删除序言中不相关的内容后,下面的代码完成。
\documentclass[12pt,twoside]{report}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmode=normal,
ymode=normal,
log ticks with fixed point,
%axis lines=center,
grid=both,
scale only axis=true,
%ymin=0, ymax=.0025,
%xmin=0, xmax=1,
%xtick distance=2,
legend pos=outer north east,
clip mode=individual,
%axis lines=middle,
title=Second Circuit DC Mode(Normal Graph),
ylabel=Voltage\,(V),
xlabel=Time\,(S),
%scaled ticks=true,
%enlargelimits=0.2,
%x axis line style={shorten >=-35pt, shorten <=-35pt},
%x label style={xshift=35pt},
%y axis line style={shorten >=0pt, shorten <=-35pt},
%y label style={yshift=-5pt},
]
\addplot[opacity=.7,
only marks,
mark=triangle*,
red
]
table {
x y
0 10
30 7.42
60 5.57
90 4.25
120 3.25
150 2.49
180 1.92
210 1.47
240 1.14
270 0.895
300 0.696
330 0.552
360 0.433
390 0.342
420 0.276
450 0.221
480 0.181
510 0.149
540 0.124
570 0.104
600 0.089
};
\addplot [opacity=.5] table[
y={create col/linear regression={y=Y, ymode=log}}] % compute a linear regression from the input table
{
X Y
0 5.599164502
30 5.237209957
60 4.875255411
90 4.513300866
120 4.15134632
150 3.789391775
180 3.427437229
210 3.065482684
240 2.703528139
270 2.341573593
300 1.979619048
330 1.617664502
360 1.255709957
390 0.893755411
420 0.531800866
450 0.16984632
%480 -0.192108225
%510 -0.554062771
%540 -0.916017316
%570 -1.277971861
%600 -1.639926407
};
\end{axis}
\end{tikzpicture}
\end{document}