I would like to specify xmode and ymode for the axis with \pgfplotsset (or any other way, so that the mode can be changed by an if statement) The error message which I get is:
! Package pgfplots Error: Sorry, you can't change `/pgfplots/xmode' in this con
text. Maybe you need to provide it as \begin{axis}[/pgfplots/xmode=...] ?.
Here is a minimal working example:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5}
\def\someoption{1} % change this to zero to see the error
\ifcase\someoption % this is the reason why I want to define xmode with styles
\pgfplotsset{/pgfplots/mystyle/.style={
/pgfplots/xmode=log, % this is not working
/pgfplots/ymode=log % this too
}}
\else
\pgfplotsset{/pgfplots/mystyle/.style={}}
\fi
\begin{document}
\section*{with style: (not working)}
\begin{tikzpicture}
\begin{axis}[/pgfplots/mystyle]
\addplot coordinates {(10, 100) (100, 15) (2000, 200)};
\end{axis}
\end{tikzpicture}
% how it should look like
\section*{with hard-coded axis properties:}
\begin{tikzpicture}
\begin{axis}[xmode=log,ymode=log]
\addplot coordinates {(10, 100) (100, 15) (2000, 200)};
\end{axis}
\end{tikzpicture}
\end{document}
This is related to Axis limits in user-defined style, but this doesn't help in this case.
semilogxaxis,semilogyaxisandloglogaxis. Why can't you use them? – Claudio Fiandrino Jul 28 '12 at 17:16