I'm trying to generate glyph plot. The idea is that I've a list of elements with 4 values (0.0 .. 1.0) that represent the value of a particular characteristic. My goal is to connect those points but I cannot access the data within the elements array. I tried some macros, and using \pgfmathparse
with no success. Here's an example of what I'm trying to do:
\documentclass{standalone}
\usepackage{pgfmath,pgffor}
\begin{document}
\def\elements{{0.5,0.5,0.59,0.5}, {0.2,0.5,0.5,0.8} }% romboide and a diamond shape
\foreach \elementPoints [count=\i] in \elements {
\draw ({2.2*\i},0) ++(\elementPoints[1],0) node (a) {}
({2.2*\i},0) ++(0,\elementPoints[2]) node (b) {}
({2.2*\i},0) ++({-1*\elementPoints[3]},0) node (c) {}
({2.2*\i},0) ++(0,{-1*\elementPoints[4]}) node (d) {};
\draw (a) -- (b) -- (c) -- (d) -- (a);
}
\end{document}
Thanks
Best Answer
You have a few errors in your code:
You load only the packages
pgfmath
andpgffor
but nottikz
, yet you use\draw
and TikZ’s path syntax. Though, they also need thetikzpicture
environment (or the\tikz
macro).The index of the PGFmath arrays start at
0
not1
.The arrays in the
\elements
macro need another set of braces{ }
so as do indicate that they are in fact arrays, the first pair of braces are stripped away when\foreach
splits the list in its two arrays.Furthermore, you use
node
s which are by default of the shaperectangle
and have vertical and horizontal dimensions. This, I believe, is not what you want. Usecoordinate
s if you simply want to save a coordinate under a name:Instead of saving the coordinates and connecting them later, you can also connect them direct on the path.
Eitherway, maybe you are interested in a shorter version of your code using an
insert path
style and polar coordinates (which could have been used in your example, too).References
+
and++
(section 2.15 “Specifying Coordinates”, pp. 31f.)insert path
(chapter 14 “Syntax for Path Specications”, p. 139)kite
shape in section 62.3 “Geometric Shapes”, pp. 623f.Original approach
Output (original)
Different approach
Output (different)