Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How do I set the color of a marker with one meta column in a table AND its size with another meta column?

So in this minimal working example, how can I set the marker size with 'w1' and the color with 'w2'?

\begin{filecontents*}{temp.dat}
x y w1 w2
1 1 2 4
2 2 1 3
3 3 4 2
4 4 3 1
\end{filecontents*}

\documentclass[10pt,a4paper]{report}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[]
\addplot[scatter,
only marks,
scatter src=explicit,
scatter/@pre marker code/.append style={/tikz/mark size=2+\pgfplotspointmetatransformed/300}]
table[x=x,y=y,meta=w1]{temp.dat};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

You can use the visualization depends on=<expr>\as<macro> key for to make another variable available. If you set visualization depends on=\thisrow{w2}\as\wtwo, the content of the w2 column will be available as a macro called \wtwo:

\begin{filecontents*}{temp.dat}
x y w1 w2
1 1 2 4
2 2 1 3
3 3 4 2
4 4 3 1
\end{filecontents*}

\documentclass[10pt,a4paper]{report}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[]
\addplot[
    scatter,
    only marks,
    scatter src=explicit,
    visualization depends on=\thisrow{w2}\as\wtwo,
    scatter/@pre marker code/.append style={
        /tikz/mark size=\wtwo
    }
]
table[x=x,y=y,meta=w1]{temp.dat};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Why did you put the filecontents* before the documentclass? –  Oh my ghost Feb 17 '13 at 21:22
    
@GarbageCollector: Because that's what the OP did. But you're right, I was surprised by that as well. Seems to work fine though. –  Jake Feb 17 '13 at 21:24
    
There is a drawback if we put the filecontents* before the document class because TeX is unable to rewrite the temp.dat even though \usepackage{filecontents} exists in the preamble. –  Oh my ghost Feb 17 '13 at 21:37
    
@GarbageCollector: Yeah, I know. That's not the case here, though. –  Jake Feb 17 '13 at 21:37
1  
By design, in the beginning filecontents environment can only be used before the \documentclass and it cannot overwrite the existing file. But later the developers made a hacked-up version by providing us with filecontents package. This package must be loaded if we want to let TeX overwrite the existing file. No need to load filecontents package if you just want to invoke filecontents environment in the preamble. –  Oh my ghost Feb 18 '13 at 5:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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