pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
200 stars 35 forks source link

Usage of "declared functions" in different axis options not consistent #143

Open pgf-tikz-bot opened 8 years ago

pgf-tikz-bot commented 8 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/143/ Author: mo-gul Timestamp: 2016-10-25 17:57:13.943000

While writing this answer I recognized that I cannot use "declared functions" in (extra) ticks while it is no problem to use them for the axis limits. Is that a bug or a feature?

% ----- minimal example -----
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}[
        declare function={
            ymin=-4;
            ymax=1;
        },
    ]
            \pgfmathsetmacro{\xmin}{-2}
            \pgfmathsetmacro{\xmax}{3}
        \begin{axis}[
            % while using macros seems not to be a problem "anywhere" ...
            xmin=\xmin,xmax=\xmax,
            xtick={\xmin,\xmax},
            extra x ticks={\xmin,\xmax},
            % ---
            % ... it is also not a problem to use "declared functions" to
            % define the axis limits, ...
            ymin=ymin,ymax=ymax,
%            % ...but why can't I use them to provide values for the ticks?
%            % Is this a bug or a feature
%            ytick={ymin,ymax},
%            extra y ticks={ymin,ymax},
            % -----
        ]
            \addplot coordinates { (0,0) };
        \end{axis}
    \end{tikzpicture}
\end{document}
% ---------------------------
pgf-tikz-bot commented 7 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/143/#e99d Author: symbol-1 Timestamp: 2017-07-17 10:15:41.800000

(There is no yticks. I assume ytick) According to the manual, the argument of ytick is put inside a \foreach\y in{<argument>}. According to experiments, the argument of extra y ticks is put inside a \foreach as well.

And since \foreach searchs for and returns literal patterns such as A(0),A(...),A(9), I do not think it is possible to evaluate functions (including 0-ary functions).

pgf-tikz-bot commented 7 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/143/#e99d/efa6 Author: mo-gul Timestamp: 2017-07-17 16:54:06.565000

Sure, I meant ytick instead of yticks. I'll correct that in a minute.

So you mean that there is no possibility to check (in something like a "special handler") for a function? Because I don't find it useful to write something like \pgfmathsetmacro{\ymin}{ymin} ...

pgf-tikz-bot commented 7 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/143/#e99d/efa6/0d1f Author: symbol-1 Timestamp: 2017-07-21 16:12:21.925000

There is an alternative of \pgfmathsetmacro: use \usetikzlibrary{math} and then \tikzset{evaluate={\ymin=-4;\ymax=1;}}.


By the way, there is another key called /pgf/foreach/evaluate=⟨variable⟩as⟨macro⟩using⟨formula⟩. In other words,

\foreach \x [evaluate=\x] in {2^0,2^...,2^8}{$\x$, }

will result in 1.0, 2.0, ..., 256.0 instead of the literal pattern.