嗨,我想绘制负载电压与负载电流的图表,我一直在尝试用 来做tikzpicture
,但不知道是否可以用 来做tikzplot
?下面的代码就是我想要的,我想绘制数据并测量梯度并获得yintercept
,我对使用 还很陌生,pgfplot
所以对我来说学习曲线相当陡峭。我的绘图点将是
P1(0.750,7.50)
P2(0.409,8.192)
P3(0.281,8.437)
...
我可以找出该直线的方程并将其作为标签吗?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [ultra thick,-latex] (0,0)--(10,0) node [right, above]{$I_L$ Load Current};
\draw [ultra thick,-latex] (0,0)--(0,12) node [right]{$V_L$Load Voltage};
\coordinate (X2) at (4,0);
\coordinate (X1) at (6,0);
\coordinate (P1) at (0,5);
\coordinate (P2) at (0,7);
\coordinate (b) at (4,5);
\coordinate (d) at (6,7);
\coordinate (a) at (4,7);
\coordinate (c) at (6,5);
\node at (X2) [below] {$X2$};
\node at (X1) [below] {$X1$};
\node at (P2) [left] {$P2$};
\node at (P1) [left] {$P1$};
\draw [dashed] (a)node [above right] {$a$}--(X2);
\draw [dashed] (d)node [above right] {$d$}--(X1);
\draw [dashed] (P1)--(c)node [above right] {$c$};
\draw (P2)--(d)node [above right] {$d$};
\node at (b) [above right]{$b$};
%\draw (d)--++(0:2)node [right] {$ MC=AC$};
\draw (c)--(a)--++(135:5.65);
\draw (c)--++(-45:2) node [below] {$D$};
\end{tikzpicture}
\end{document}
这是我目前所拥有的,但无法让它看起来像上面的例子。我想从我的一些数据点中取出虚线
\documentclass[convert = false, border=10pt]{standalone}
% http://sourceforge.net/projects/pgfplots/
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{steinmetz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=Voltage,
ylabel=Current]
\addplot[color=blue,mark=x] coordinates {
(0.750,7.5)
(0.409,8.192)
(0.2812,8.437)
(0.2143,8.571)
};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这是一个可能的解决方案,利用了库中的线性回归pgfplotstable
。计算线性模型并显示在图例中。Y interception
也显示在图中。
代码
\documentclass[convert = false, border=10pt]{standalone}
% http://sourceforge.net/projects/pgfplots/
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{amsmath}
\usepackage{steinmetz}
\usepackage{filecontents}
\usetikzlibrary{positioning}
\begin{filecontents}{data.csv}
X Y
0.750 7.5
0.409 8.192
0.2812 8.437
0.2143 8.571
};
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=1,ymin=7,ymax=10,
xlabel=Voltage,clip=false,
ylabel=Current,
anchor=south,
legend cell align = left,
legend pos = north east,
every axis x label/.style={at={(current axis.south east)},below=7mm, anchor=east},
]
% raw datum read from an input file called data.csv
\addplot[color=blue,mark=x] table[row sep=\\,x=X,y=Y]{data.csv};
\addlegendentry{Linear function}
% -- linear regression
\addplot+[no markers,red] table[row sep=\\,
y={create col/linear regression={y=Y}}]{data.csv};
\addlegendentry{linear trend $\left(y=\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}\right)$}
% -- extrapolation to find intersections.
\addplot+[no markers,red,shorten >=-2cm] table[row sep=\\,
y={create col/linear regression={y=Y}}]{data.csv};
% -- labelling
\draw[dashed] (axis cs: 0,8.571)node[xshift=0.3cm,pin={left:$P_1$}]{}--(axis cs: 0.2143,8.571);
\draw[dashed] (axis cs:0,8.192)node[xshift=0.3cm,,pin={left:$P_2$}]{}--(axis cs: 0.409,8.192) |-
(axis cs:0,7)node[pos=0.5,pin={below:$X_2$},inner sep=0pt]{};
\draw[dashed] (axis cs: 0,8.571)-|(axis cs: 0.409,8.192);
\draw[dashed] (axis cs: 0.2143,8.571) |- (axis cs:0,7)node[pos=0.5,pin={below:$X_1$},inner sep=0pt] {};
\end{axis}
\end{tikzpicture}
\end{document}