我試圖根據外部計算的船體節點在圖中說明船體。為此,我使用\closedcycle
填充相應點包圍的船體。
第一個船體是根據四個數據點繪製的,從而產生預期的梯形船體形狀(黃色填充)。
第二個船體的形狀相當不規則,總共由八個數據點描述。然而,使用適用於黃色船體的方法,會為第二個船體(藍色填充)產生錯誤的繪圖:
- 船體似乎向下延伸至 x 軸
- 船體填充中缺少向下延伸到 x 軸的部分
- 如為說明而繪製的資料點所示(註解掉該圖以查看藍色船體右上角缺少的船體部分),船體向下延伸到 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;