我正在制作热力学 PV 图来显示循环如何进行,理想情况下,我需要添加沿蓝线向左、红线向右和绿线向上的箭头。但我无论如何也找不到任何地方表明可以这样做。
这是我的代码:
\begin{tikzpicture}
\begin{axis}[
xlabel=$V$,
ylabel=$P$,
ymin=0,
ymax=3.5e5, % Changed to 3.5e5 to include the third function properly
xmin=19,
xmax=41,
grid=both,
legend pos=outer north east,
legend style={font=\footnotesize},
width=10cm,
height=6cm,
]
\addplot[blue, domain=20:40, samples=100] {4011230/x};
\addlegendentry{$P_1 = \frac{4011230}{V_1}$};
\addplot[red, domain=20:40, samples=100] {29768029/(x^1.67)}; % Corrected the power notation
\addlegendentry{$P_2 = \frac{29768029}{V_2^{1.67}}$};
\addplot[green] coordinates {(40,62850) (40,100000)};
\addlegendentry{$V_3 = 40$};
\end{axis}
\end{tikzpicture}
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{nicefrac}
\usetikzlibrary{decorations.markings, arrows.meta}
\tikzset{
arr/.style={decoration={markings,
mark=at position 0.25 with {\arrow{Stealth}},
mark=at position 0.50 with {\arrow{Stealth}},
mark=at position 0.75 with {\arrow{Stealth}},
},postaction={decorate}},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=10cm, height=6cm,
xmin=19, xmax=41,
ymin=0, ymax=3.5e5,
xlabel=$V$, ylabel=$P$,
grid=both,
legend pos=outer north east,
legend style={font=\footnotesize},
]
\addplot[blue, arr, domain=40:20, samples=100] {4011230/x};
\addlegendentry{$P_1=\nicefrac{4011230}{V}$};
\addplot[red, arr, domain=20:40, samples=100] {29768029/(x^1.67)};
\addlegendentry{$P_2=\nicefrac{29768029}{V^{1.67}}$};
\addplot[green, -Stealth] coordinates {(40,{29768029/(40^1.67)}) (40,4011230/40)};
\addlegendentry{$V=40$};
\end{axis}
\end{tikzpicture}
\end{document}