
我希望最後一段是白色的,但最後一段似乎是與前一段結合在一起的。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfmathdeclarefunction{vdw}{0}{\pgfmathparse{8.314*115/(x-0.0000364)-0.1358/x/x}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis y line = left,
axis x line = bottom,
xlabel = $V$,
ylabel = $P$,
samples = 500,
domain = 0.00005:0.0005,
xmin = 0, xmax = 0.00055,
ymin = 0, ymax = 5*10^6,
]
\addplot[name path=vdw, black, thick, mark=none, ] {vdw};
\addplot[name path=line, gray, no markers, line width=1pt] {2.0*10^6};
\addplot fill between[
of = vdw and line,
split, % calculate segments
every segment no 0/.style={white},
every segment no 1/.style={orange},
every segment no 2/.style={red},
every segment no 3/.style={white},
];
\end{axis}
\end{tikzpicture}
\end{document}
答案1
引用 PGFPLOTS 手冊(第 5.6.8 節陷阱與局限性,第 390 頁),
第一個限制是可擴展性。如果樣本數量很大,底層演算法的效率相對較低,且擴展性很差。請將其應用於合理的樣本量「和具有合理交叉點數量的圖」。這意味著:如果花費的時間太長,您可能需要降低採樣密度。
因此,如果您稍微減少樣本數量(想像一下您的步驟有 500 個樣本;9x10^{-7}
太密集),它將給出正確的結果。在這裡,我samples = 200
只是透過反覆試驗的方法來選擇。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\usepgfplotslibrary{fillbetween}
\pgfmathdeclarefunction{vdw}{0}{\pgfmathparse{8.314*115/(x-0.0000364)-0.1358/x/x}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis y line = left,
axis x line = bottom,
xlabel = $V$,
ylabel = $P$,
samples = 200,
domain = 0.00005:0.0005,
xmin = 0, xmax = 0.00055,
ymin = 0, ymax = 5*10^6,
]
\addplot[name path=vdw, black, thick, mark=none, ] {vdw};
\addplot[name path=line, gray, no markers, line width=1pt] {2.0*10^6};
\addplot fill between[
of = vdw and line,
split, % calculate segments
every segment no 0/.style={white},
every segment no 1/.style={orange},
every segment no 2/.style={red},
every segment no 3/.style={white},
];
\end{axis}
\end{tikzpicture}
\end{document}