pgfplots の塗りつぶしが間違ったセグメント分割で行われる

pgfplots の塗りつぶしが間違ったセグメント分割で行われる

最後のセグメントを白にしたいのですが、最後のセグメントが前のセグメントと結合されているようです。

ここに画像の説明を入力してください

\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} 

関連情報