2
  1. How do I exclude certain coordinates from being smoothed by the "smooth" option in a PGF plot?
  2. How do I avoid that \closedcycle jumps to zero?

Here is my example:

\documentclass{minimal}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture} 
\begin{axis}[
axis lines=center,
xtick=\empty,
ytick=\empty,
plot a/.style={semithick,red,smooth},
plot b/.style={semithick,blue,smooth},
plot error/.style={thick,orange,smooth},
]

\addplot[plot a] coordinates {
(1.400,0.484) (1.450,0.464) (1.500,0.442) (1.550,0.419) (1.600,0.395) (1.650,0.370)
(1.700,0.346) (1.750,0.321) (1.800,0.297) (1.850,0.273) (1.900,0.249) (1.950,0.227)
(2.000,0.205) (2.050,0.185) (2.100,0.166) (2.150,0.148) (2.200,0.131) (2.250,0.116)
(2.300,0.102) (2.350,0.089) (2.400,0.077) (2.450,0.067) (2.500,0.057) };

\addplot[plot b] coordinates {
(1.400,0.111) (1.450,0.120) (1.500,0.130) (1.550,0.139) (1.600,0.150) (1.650,0.160)
(1.700,0.171) (1.750,0.183) (1.800,0.194) (1.850,0.206) (1.900,0.218) (1.950,0.230)
(2.000,0.242) (2.050,0.254) (2.100,0.266) (2.150,0.278) (2.200,0.290) (2.250,0.301)
(2.300,0.312) (2.350,0.323) (2.400,0.333) (2.450,0.343) (2.500,0.352) };

\addplot[plot error] coordinates{
(2.300,0.312) (2.250,0.301) (2.200,0.290) (2.150,0.278) (2.100,0.266) (2.050,0.254)
(2.000,0.242) (1.950,0.230) (1.946,0.2287) (1.950,0.227) (2.000,0.205) (2.050,0.185)
(2.100,0.166) (2.150,0.148) (2.200,0.131) (2.250,0.116) (2.300,0.102) } \closedcycle;

\end{axis}
\end{tikzpicture}
\end{document}

Resulting plot

The problems are twofold:

  1. The left corner of the orange triangle is plotted wrongly due to smoothing. (One can see that more easily, if one zooms into the resulting PDF.) I need the smooth option such that the orange plot follows the blue plot (first half) and the red plot (second half) correctly. But the point at which the orange plot stops following the blue plot and starts following the red plot must no be smoothed, because it is a non-differentiable point. Is there any option how single points of a plot can be excluded from smoothing?
  2. The orange plot is terminated by \closedcycle because I want to use the fill option later. But this makes the plot jump to zero first as one can see from the picture. Is there any option to close a plot by a straight line from the end to the start point?
4

If you can use most recent pgfplots version (1.10), it includes a new fillbewteen library which can fill any area between two curves.

You need to assign a name to every path (name path=) and later use these names to fill areas between them.

With this solution there is no problem with 'smoothornon-differentiable points`.

\documentclass[border=3mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.9}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture} 
\begin{axis}[
axis lines=center,
xtick=\empty,
ytick=\empty,
plot a/.style={semithick,red,smooth},
plot b/.style={semithick,blue,smooth},
plot error/.style={thick,orange,smooth},
]

\addplot[plot a, name path=A] coordinates {
(1.400,0.484) (1.450,0.464) (1.500,0.442) (1.550,0.419) (1.600,0.395) (1.650,0.370)
(1.700,0.346) (1.750,0.321) (1.800,0.297) (1.850,0.273) (1.900,0.249) (1.950,0.227)
(2.000,0.205) (2.050,0.185) (2.100,0.166) (2.150,0.148) (2.200,0.131) (2.250,0.116)
(2.300,0.102) (2.350,0.089) (2.400,0.077) (2.450,0.067) (2.500,0.057) };

\addplot[plot b, name path=B] coordinates {
(1.400,0.111) (1.450,0.120) (1.500,0.130) (1.550,0.139) (1.600,0.150) (1.650,0.160)
(1.700,0.171) (1.750,0.183) (1.800,0.194) (1.850,0.206) (1.900,0.218) (1.950,0.230)
(2.000,0.242) (2.050,0.254) (2.100,0.266) (2.150,0.278) (2.200,0.290) (2.250,0.301)
(2.300,0.312) (2.350,0.323) (2.400,0.333) (2.450,0.343) (2.500,0.352) };

%\addplot[plot error, name path=C] coordinates{
%(2.300,0.312) (2.250,0.301) (2.200,0.290) (2.150,0.278) (2.100,0.266) (2.050,0.254)
%(2.000,0.242) (1.950,0.230) (1.946,0.2287) (1.950,0.227) (2.000,0.205) (2.050,0.185)
%(2.100,0.166) (2.150,0.148) (2.200,0.131) (2.250,0.116) (2.300,0.102) } \closedcycle;

%\draw[name path=vertical] (axis cs:2.3,0)--(axis cs:2.3,5);

\addplot[fill=none] fill between [of=A and B,
    soft clip={domain=1:2.3},
    split,
    every segment no 1/.style={fill=orange}];
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.