PGFPlots – Plotting Third Variable as Color Gradient

pgfplotstikz-pgf

I'm trying to use pgfplots to create a 2D plot with 3 variables, the third one being plotted as a color gradient.

\begin{tikzpicture}[scale=0.75]
\begin{axis}[xlabel=Selta,ylabel={Hitastig $[\si{\celsius}]$},colorbar,colormap/greenyellow]
\addplot[mesh,ultra thick]
    table[x=S,y=POT_T,z=DB, col sep=semicolon]{287.csv};
\legend{Stöð 287}
\end{axis}
\end{tikzpicture}

I've been looking all over in the pgfplots manual, but I have somehow overlooked how to plot the z variable as the color gradient, this code automatically assumes the y variable is to be plotted.

It always seems problems like these are something incredibly easy that was overlooked, so I hope this will be solved in no time.

Thanks in advance :).

Edit:

Although I found the answer to this specific problem, there is another very related matter I'd like an answer to, mods correct me if this should be a separate question.

I'd like to reverse the colorbar, and have found the code to do so is to put colorbar style={z dir=reverse} into the axis options. But as per the previous answer I can't use z as the variable name (or can I?) and pgfplots doesn't accept colorbar style={point meta dir=reverse}.

How would this be achieved, or how to answer the previous question in a way that lets you reverse the colorbar?

Best Answer

Adding to your answer: You can "fake" the reversed colorbar by rotating it and putting the labels on the other side. A colorbar is essentially another axis, so all the styles you get with normal axes can be used.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[scale=0.75]
\begin{axis}[colorbar,colormap/cool,
  colorbar style={xshift=1cm,
    yticklabel pos=left,
    yticklabel style={anchor=west},
    rotate=180}]
\addplot[scatter,point meta=explicit,ultra thick,point meta min={1}, point meta max={700}]
    table[x=S,y=POT_T, meta=DB, col sep=semicolon]{
      S;POT_T;DB
      0;0;650
      1;0.5;400
      2;2;150
};
\end{axis}
\end{tikzpicture}

\end{document}

axis with pseudo-reversed colorbar