- 如何通过 PGF 图中的“平滑”选项排除某些坐标的平滑处理?
- 我该如何避免
\closedcycle
跳转到零?
以下是我的示例:
\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}
问题有两个方面:
- 由于平滑处理,橙色三角形的左角绘制错误。(如果放大生成的 PDF,可以更容易地看到这一点。)我需要一个
smooth
选项,使橙色图正确地跟随蓝色图(前半部分)和红色图(后半部分)。但是,橙色图停止跟随蓝色图并开始跟随红色图的点不能被平滑处理,因为它是一个不可微分的点。是否有任何选项可以将图中的单个点排除在平滑处理之外? - 橙色图以 结束,
\closedcycle
因为我想fill
稍后使用该选项。但这会使图先跳转到零,如图片所示。是否有任何选项可以通过从终点到起点的直线关闭图?
答案1
如果你可以使用最新的pgfplots
版本(1.10),它包含一个fillbewteen
可以填充两条曲线之间任意区域的新库。
您需要为每个路径指定一个名称(name path=
),然后使用这些名称来填充它们之间的区域。
有了这个解决方案,就不存在“光滑or
不可微点”的问题了。
\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}