Pgfplots \closedcycle 未正确填充

Pgfplots \closedcycle 未正确填充

我试图根据外部计算的船体节点在绘图中描绘船体。为此,我使用\closedcycle填充相应点所包围的船体。

第一个船体是根据四个数据点绘制的,结果呈现出预期的梯形船体形状(黄色填充)。

第二艘船的形状相当不规则,总共由八个数据点描述。但是,使用适用于黄色船体的方法,会为第二艘船体(蓝色填充)生成错误的绘图:

  1. 船体似乎延伸到了 x 轴
  2. 船体填充中缺少向下延伸至 x 轴的部分
  3. 如图示绘制的数据点所示(注释掉此图可以查看蓝色船体右上方缺失的船体部分),船体延伸至 x 轴的点不是底层数据集的一部分。

生成图表的最少代码片段:

\documentclass{article}
\usepackage{filecontents}
\usepackage{pgfplots}


\begin{filecontents}{okay_points.dat}
    hull_x;hull_y
    0.35501086786719216;0.35501086786719216
    0.3501998312158284;0.3501998312158284
    0.3501998312158284;0.0
    0.35501086786719216;0.0
\end{filecontents}

\begin{filecontents}{problematic_points.dat}
    hull_x;hull_y
    0.6268512948297316;0.6591688411952603
    0.3501998312158284;0.3501998312158284
    0.35501086786719216;0.35501086786719216
    0.6278876657471278;0.6560286756711164
    0.6330607325983083;0.6624668180953179
    0.6330598364108084;0.6638809669603063
    0.6322766634159019;0.6639305124049031
    0.6280718253300845;0.6603345843906823
\end{filecontents}


\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            no markers,
            %
            xmin = 0.25,
            xmax = 0.7,
            ymin = 0.25,
            ymax = 0.7,
            ]

            \pgfplotstableread[col sep=semicolon]{okay_points.dat}\okay
            \pgfplotstableread[col sep=semicolon]{problematic_points.dat}\problem

            % -- okay --
            % use closedcycle to plot hull using data points
            \addplot+[fill=yellow, draw=none] table[x = hull_x, y = hull_y]{\okay}\closedcycle;


            % -- problematic --
            % use closedcycle to plot hull using data points
            \addplot+[fill=blue, draw=none] table[x = hull_x, y = hull_y]{\problem}\closedcycle;
            % --> problem: hull extended to the x-axis (thin line) and filled section missing in upper part of hull

            % plot points to illustrate hull node points
            \addplot+[only marks, mark options = {thin, solid}, gray] table[x = hull_x, y = hull_y]{\problem};
            % --> comment out / disable line to see section missing in upper part of hull (otherwise covered by point markers)
            % --> hull node points do not include values with y < 0.25: Why is filled area extended to x-axis?
        \end{axis}
    \end{tikzpicture}
\end{document}

如上所述,获得的图中所示的蓝色船体错误地延伸至 x 轴,并且其填充在相应区域缺少部分(因此,我假设这两个问题是相互关联的):

船体图 缺少填充

答案1

备注:总结@JasperHabicht 的评论,以便将该问题标记为已解决。

使用-- cylce而不是\closedcycle解决了这个问题。为了完整起见,下面总结了相关的代码行。


\addplot+[fill=yellow, draw=none] table[x = hull_x, y = hull_y]{\okay}\closedcycle;

变成

\addplot+[fill=yellow, draw=none] table[x = hull_x, y = hull_y]{\okay} -- cycle;

\addplot+[fill=blue, draw=none] table[x = hull_x, y = hull_y]{\problem}\closedcycle;

变成

\addplot+[fill=blue, draw=none] table[x = hull_x, y = hull_y]{\problem} -- cycle;

相关内容