1

I am trying to illustrate a hull in a plot based on externally calculated hull nodes. For this, I use \closedcycle to fill the hull enclosed by the corresponding points.

The first hull is plotted based on four data points, resulting in a somehow trapezoidal hull shape as expected (yellow infill).

The second hull has a rather irregular shape and is described by eight data points in total. However, using the approach working for the yellow hull, produces in incorrect plot for the second hull (blue infill):

  1. The hull seems to be extended down to the x-axis
  2. The section extended down to the x-axis is missing in the hull fill
  3. As indicated by the data points plotted for illustration (comment out this plot to see the missing hull section at the top right of the blue hull), the points the hull is extended down to x-axis is not part of underlying dataset.

Minimum code snippet to produce the plot:

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

As elaborated, the blue hull illustrated in the obtained plot is incorrectly extended down to the x-axis and its infill has a missing section at the corresponding region (therefore, I assume both problems are linked to each other):

hull plot missing infill

2
  • 1
    See this Q&A: Replace \closedcycle by -- cycle. Commented Apr 26 at 18:39
  • 1
    @JasperHabicht: Thanks. This solved my problem.
    – albert
    Commented Apr 26 at 18:58

1 Answer 1

3

Remark: Summarizing @JasperHabicht's comment to be able to mark this question as solved.

Using -- cylce instead of \closedcycle solved the issue. For the sake of completeness, relevant lines of code are summarized below.


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

becomes

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

becomes

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .