
마지막 세그먼트를 흰색으로 하고 싶은데 마지막 세그먼트가 이전 세그먼트와 합쳐진 것 같습니다.
\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절함정과 한계, p.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}