
Ich möchte ein Ti erstellenkz-Plot, bei dem ein Zahlenvektor verwendet wird, um ein Bild einzufügen. Ich möchte, dass das Bild mit dem aktuellen Wert skaliert wird, sodass die Bilder weiter oben y-axis
größer sind als die mit den niedrigeren Werten. Irgendwie erhalte ich immer den Fehler„Unzulässige Maßeinheit (pt eingefügt)“wenn ich versuche, meine Variable im Breitenargument zu verwenden. Das habe ich bisher getan:
\begin{tikzpicture}
\foreach \y [count=\x] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\x,\y) {\includegraphics[width=\y*0.2cm]{../figs/Potato.png}};
\end{tikzpicture}
Antwort1
\includegraphics
analysiert im Gegensatz zu pgf die Argumente seiner Schlüssel nicht, Sie müssen also analysieren.
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \y [count=\x] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\x,\y) {\pgfmathparse{\y*0.2}\includegraphics[width=\pgfmathresult cm]{example-image-duck}};
\end{tikzpicture}
\end{document}
Übrigens, \x
und \y
wird auch von der Bibliothek verwendet calc
. Ich persönlich würde also vielleicht verwenden
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \Y [count=\X] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\X,\Y) {\pgfmathparse{\Y*0.2}\includegraphics[width=\pgfmathresult cm]{example-image-duck}};
\end{tikzpicture}
\end{document}
um auf der sicheren Seite zu sein, falls ich mich später für die Verwendung calc
in der Schleife entscheide.
Antwort2
Es ist möglich, die Berechnungen in einer Schleife durchzuführen foreach
und zu vermeiden\pgfmathparse
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \y [count=\x, evaluate=\y as \width using \y*0.2] in {0.5, 0.7, 0.8, 0.9, 0.95, 1, 1.05, 1.07, 1.2, 1.205, 2, 3, 3.1, 5, 5.4, 5.8, 6.1, 6.15, 6.125, 6.4}
\node at(\x,\y) {\includegraphics[width=\width cm]{example-image}};
\end{tikzpicture}
\end{document}