tikz 中用 [fill=black!\pgfmathresult] 着色节点的问题

tikz 中用 [fill=black!\pgfmathresult] 着色节点的问题

我尝试使用 tikz 根据数组文件中的值用颜色填充节点,但是当通过 [at (a,b)] 固定节点位置时,我无法用正确的颜色填充节点:

\begin{document}
The data in the 6,3 position of the file is \arqa[6,3]\\
\begin{tikzpicture}
%\tikzstyle{vertex}=[circle,fill=black!50,minimum size=17pt,inner sep=0pt]
\tikzstyle{vertex}=[shape=rectangle,draw=black,fill=black!\pgfmathresult]
\pgfmathparse{\arqa[6,3]}
\node  at (6,3)[vertex,fill=black!\pgfmathresult] (G-6,4);
\node  at (6,4)[vertex,fill=black!50.2] (G-6,5);
\node [vertex,fill=black!\pgfmathresult] (G-6,6);
\end{document}

输出的pdf是这样的在此处输入图片描述

因此节点“\node 位于 (6,3)[vertex,fill=black!\pgfmathresult] (G-6,4);“没有用“black!50.20”填充黑色,但是节点“\node [vertex,fill=black!\pgfmathresult] (G-6,6);“ 用正确的颜色填充,不带 [在(6,3)] 的位置。有人能帮助我吗?

答案1

Tikz 在使用时会执行一些计算\node,然后覆盖存储在的数字\pgfmathresult。下面是一些应该可以工作的代码(我在其中添加了一个小表来定义值\arqa):

\documentclass[10pt,a4paper]{article}

\usepackage{tikz}
\usepackage{pgfplotstable}

\usepackage{filecontents}
\begin{filecontents}{table.dat}
    0   25
    75  100
\end{filecontents}

\begin{document}
\pgfplotstableread{table.dat}{\arqa}
\pgfplotstablegetelem{0}{1}\of{\arqa}
\pgfmathsetmacro\result{\pgfplotsretval}

The data in the 6,3 position of the file is \result\\

\begin{tikzpicture}
%\tikzstyle{vertex}=[circle,fill=black!50,minimum size=17pt,inner sep=0pt]
\tikzstyle{vertex}=[shape=rectangle,draw=black,fill=black!\result]
\node  at (6,3)[vertex,fill=black!\result]{};
\node  at (6,4)[vertex,fill=black!50.2] {};
\node [vertex,fill=black!\result] {};
\end{tikzpicture}

\end{document}

相关内容