我只创建这个:
有了这个:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=left,
ultra thick,
y coord trafo/.code={\pgfmathparse{sqrt(#1)}},
y coord inv trafo/.code={\pgfmathparse{pow(#1,2)}}
]
\addplot coordinates {
(0,0)
(0.3,0)
(0.44,0.00016)
(0.45,0.00045)
(0.49,0.00071)
(0.5,0.001)
(0.51,0.00139)
(0.54,0.00176)
(0.56,0.00214)
(0.57,0.00243)
(0.61,0.00279)
(0.63,0.00327)
(0.64,0.00386)
(0.67,0.00433)
};
\end{axis}
\end{tikzpicture}
\end{document}
但我需要输入负坐标,例如:(-0.51,-0.00139)
我还需要红线和文字(I,V):
答案1
- 通过设置
axis lines=middle
,一旦添加负坐标,两个轴都会位于中间。 - 您可以使用
xlabel=$V$
和添加标签ylabel=$I$
。 - 可以使用 将这些标签放置在相对于轴的不同位置
x label style={at={(current axis.right of origin)}, anchor=west}
。 - 可以使用 绘制红线
\draw[red, dashed] (axis cs:0.6, 0)--(axis cs:0.6, 0.004);
。这里我使用axis cs
坐标,即链接到轴的坐标。 - 您的最后一个请求无法实现。您无法在 y 轴上添加负值,因为您使用平方根重新缩放轴。负数的平方根是一个复数。
举个例子,我删除了一些y coord travo
东西,并添加了一些负坐标。
平均能量损失
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
ultra thick,
xlabel= $V$, ylabel=$I$,
x label style={at={(current axis.right of origin)}, anchor=west},
% y coord trafo/.code={\pgfmathparse{sqrt(#1)}},
% y coord inv trafo/.code={\pgfmathparse{pow(#1,2)}},
]
\addplot coordinates {
(-0.48, -0.002)
(-0.43, -0.0002)
(-0.3, -0.0001)
(0,0)
(0.3,0)
(0.44,0.00016)
(0.45,0.00045)
(0.49,0.00071)
(0.5,0.001)
(0.51,0.00139)
(0.54,0.00176)
(0.56,0.00214)
(0.57,0.00243)
(0.61,0.00279)
(0.63,0.00327)
(0.64,0.00386)
(0.67,0.00433)
};
\draw[red, dashed] (axis cs:0.6, 0)--(axis cs:0.6, 0.004);
\end{axis}
\end{tikzpicture}
\end{document}