3

I tried to use tikz to fill nodes with colors according to values in an array file, but I failed to fill nodes with right color when fixing node position by [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}

The output pdf is like this enter image description here

So the node "\node at (6,3)[vertex,fill=black!\pgfmathresult] (G-6,4);" does not fill with black color with "black!50.20", but the node "\node [vertex,fill=black!\pgfmathresult] (G-6,6);" is filled with right color without the [at (6,3)] position. Can anyone help me?

  • 1
    please eaxtend your code snippet to complete small compilable document. command \arqa is not defined ... welcome to.tex.se! – Zarko Apr 27 at 7:43
4

Tikz performs some calculations when using \node, which then overwrites the number stored in \pgfmathresult. Below some code that should work (where I've added a small table to define a value for \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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.