在轴环境内生成多个轮廓填充

在轴环境内生成多个轮廓填充

我尝试使用 pgfplots 在一个坐标系内创建多个对齐的轮廓图。但是,pdflatex 似乎在多次执行“轮廓填充”选项时冻结。我使用“surf”选项伪造了输出,因此您可以看到我期望的轮廓填充的低质量示例。轮廓填充也只适用于一个单元格,如另一幅图所示。在代码中,您可以更改\vardim1仅查看一个单元格。我确实需要根据中的数据自动生成这样的图\tabpx,\tabpy,\tabqx,\tabpy。您知道是什么导致图片冻结我的 pdflatex 吗,或者是否存在其他方法来获得所需的结果?

使用 surf 一个细胞

代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}[ht]
    \centering
    \begin{tikzpicture}[scale=0.9]
        \def\tabpx{%
            {%
            0,3,5,4.3,5.2
            }%
        }
        \def\tabpy{%
            {%
            1.5,3,5,3.1,0
            }%
        }
        \def\tabqx{%
            {%
            0.0,4,6,7.0,8
            }%
        }
        \def\tabqy{%
            {%
            0.0,0,1,4.9,0
            }%
        }
        \tikzmath{
        \eps=3; \vardim= 3; % change here
        \vardimlow = \vardim - 1; \vardimsquared = \vardim^2 - 1;
        \pox=0; \ptx=1; \poy=0; \pty=1;
        \qox=0; \qtx=1; \qoy=0; \qtyy=1;
        \essss = 0; \teee = 0;
        }
        \begin{axis}[
            view={0}{90},
            domain = 0:3,
            zmax=16,
            shader = interp,
            colormap={gray}{rgb=(1,1,1), rgb=(0.5,0.5,0.5)},
            unit vector ratio*=1 1 1,
            xmin=0,xmax=3,ymin=0,ymax=3,
            xlabel=$s$,
            ylabel=$t$,
            axis y line*=left,
            axis x line*=bottom]
            \pgfplotsinvokeforeach{0,...,\vardimsquared}
            {
                \tikzmath{
                    \essss = {Mod(#1,\vardim)};
                    \teee = (#1 - \essss) / \vardim;
                    \soh = \essss + 1;
                    \toh = \teee + 1;
                    \pox = {\tabpx[\essss]};
                    \ptx = {\tabpx[\soh]};
                    \poy = {\tabpy[\essss]};
                    \pty = {\tabpy[\soh]};
                    \qox = {\tabqx[\teee]};
                    \qtx = {\tabqx[\toh]};
                    \qoy = {\tabqy[\teee]};
                    \qtyy = {\tabqy[\toh]};
                };
                \addplot3
                [
                    % surf, %-> works
                    contour filled={number = 2, labels={false}, levels={\eps}}, % problem
                    thick,
                    domain = \essss:\soh,
                    restrict x to domain=\essss:\soh,
                    y domain = \teee:\toh,
                    samples=10
                ]
                {   
                    sqrt((((1-(x-\essss))*\pox + (x-\essss)*\ptx) - ((1-(x-\essss))*\qox + (x-\essss)*\qtx))^2+(((1-(y-\teee))*\poy + (y-\teee)*\pty) - ((1-(y-\teee))*\qoy + (y-\teee)*\qtyy))^2)
                };
                \draw[color=red] (\essss,\teee) rectangle (\soh,\toh);
            }
        \end{axis}
    \end{tikzpicture}
    \caption{\small \textit{Just one cell}.}
    \label{fig:example}
\end{figure}
\end{document}

编辑 1:我在日志中发现了这个错误(程序仍然在运行): ! Package pgfplots Error: No such element: \pgfplotsarrayselect-1\of{pgfpl@cm@internal:contourfilled@X}. 这是该问题的一个最小工作示例:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            view={0}{90},
            domain = 0:2,
            xmin=0,xmax=2,ymin=0,ymax=2]
            \pgfplotsinvokeforeach{0,...,1}
            {
                \addplot3
                [
                contour filled={number = 1, labels={false}, levels={0.25}}, % problem
                domain = #1:{#1 + 1},
                y domain = 0:1,
                samples=15
                ]
                { sqrt((x- #1 -0.5)^2+(y-0.5)^2) };
            }
        \end{axis}
    \end{tikzpicture}
\end{document}

相关内容