Usually, the meta
scale (which carries the colour information for the data points) is the same for all plots in an axis, so a given value is mapped to the same colour in all plots, which is what you want. That behaviour is controlled by the key point meta rel=<axis wide | per plot>
, with axis wide
being the default (setting it to per plot
would determine the scale for each individual \addplot
command).
However, when you use \only
, PGFplots can't see all plots at the same time anymore, so point meta rel=axis wide
has no effect - the meta
range is re-scaled for each plot. In this case, you have to fix the scale yourself, using point meta min=<lower value>, point meta max=<upper value>
in the axis
options. You shouldn't adjust the ymin
and ymax
of the colorbar style
, since this doesn't actually change the mapping of colours to values, but only influences how the colour bar is displayed (that's why your colour bar is squashed in the last two frames: The meta
range only goes from 1 to 14, but the bar is still drawn from 0 to 14).
Here's an example to show the difference. Assume we have three data points with different z (or meta
) values. In the first slide, the z values are 0, 7 and 14, mapping to dark blue, green, and dark red, respectively. In the second slide, the z values are 5, 7 and 14, so the first point should now change its colour to be almost green. The other points should remain unchanged. In the third plot, the last data point has a z value of 10, so it should become more orange.
Below is a screenshot comparing the two different approaches (setting point meta min
/ point meta max
in the left-hand column and setting colorbar style={ymin=..., ymax=...}
in the right-hand column). In the left-hand column, the behaviour is as desired: The colour bar always stretches over the same range, and the colours of the points change according to their z values. In the right-hand column, the data point with the lowest z value is always assigned the dark blue colour, and that with the highest z value is drawn in dark red, regardless of the magnitude of the z value.
\documentclass{beamer}
\usepackage{pgfplots}
\begin{document}
\begin{frame}{An Example}
\pgfplotsset{height=8cm,compat=newest}
\vspace{-1em}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel=X axis,
x tick label style={/pgf/number format/1000 sep={}}, % don't put "," in numbers
ylabel=Y axis,
nodes near coords*, % For demonstration purposes only.
scatter, scatter src=explicit, only marks, % Same options for all plots, can be given axis wide
colorbar,
colormap/bluered,
colorbar style={ylabel={Z axis}},
point meta min=0, point meta max=15,
%colorbar style={ylabel={Z axis},ymin=0,ymax=14} % Uncomment this line to see why the colorbar style approach doesn't work
]
\only<1>{\addplot coordinates {(1,1) [0] (2,2) [7] (3,3) [14] };}
\only<2>{\addplot coordinates { (1,1) [5] (2,2) [7] (3,3) [14] };}
\only<3>{\addplot coordinates {(1,1) [5] (2,2) [7] (3,3) [10] };}
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
If you know it's definitely the first occurrence, you can explicitly use \glsfirst
instead of \gls
. Something like this:
\documentclass{beamer}
\usepackage[acronym]{glossaries}
\newacronym{AMA}{AMA}{a meaningless acronym}
\begin{document}
\begin{frame}
\begin{itemize}
\item<1-> The first occurrence of the acronym \glsfirst{AMA}.
\item<1-> The second occurrence of the acronym \glstext{AMA}.
\item<2-> Something else.
\end{itemize}
\end{frame}
\glsunset{AMA}
\end{document}
Edit: Here's another approach:
\documentclass{beamer}
\usepackage[acronym]{glossaries}
\newacronym{AMA}{AMA}{a meaningless acronym}
\begin{document}
\ifglsused{AMA}
{\newcommand{\doAMA}{\gls{AMA}}}
{\newcommand{\doAMA}{\glsfirst{AMA}\glsunset{AMA}}}
\begin{frame}
\begin{itemize}
\item<1-> The first occurrence of the acronym \doAMA.
\item<1-> The second occurrence of the acronym \gls{AMA}.
\item<2-> Something else.
\end{itemize}
\end{frame}
\end{document}
Best Answer
Here is a very simple method (inspired by my own answer to Choosing styles conditionally in TikZ).
Result
Code