diff options
author | Karl Berry <karl@freefriends.org> | 2008-01-28 19:32:04 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2008-01-28 19:32:04 +0000 |
commit | a898113387e9657ab658eb9cccb60988c3a3a2cc (patch) | |
tree | 71a6fccd47c26e89685cad790a5b5930f3dc0483 /Master/texmf-dist/tex/latex/pgfplots/pgfplots.sty | |
parent | fd2cf1cc29725cf8ee1100cbd37655a0c8f51f0b (diff) |
new package pgfplots (26jan08)
git-svn-id: svn://tug.org/texlive/trunk@6435 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/pgfplots/pgfplots.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/pgfplots/pgfplots.sty | 1580 |
1 files changed, 1580 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/pgfplots/pgfplots.sty b/Master/texmf-dist/tex/latex/pgfplots/pgfplots.sty new file mode 100644 index 00000000000..daf042622ee --- /dev/null +++ b/Master/texmf-dist/tex/latex/pgfplots/pgfplots.sty @@ -0,0 +1,1580 @@ +%-------------------------------------------- +% +% Package pgfplots.sty +% +% Provides a user-friendly interface to create function plots (normal +% plots, semi-logplots and double-logplots). +% +% It is based on Till Tantau's PGF package. +% +% Copyright 2007/2008 by Christian Feuersänger. +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program. If not, see <http://www.gnu.org/licenses/>. +% +%-------------------------------------------- +\def\pgfplotsversion{0.9} +\ProvidesPackage{pgfplots}[2008/26/01 Version \pgfplotsversion] +\RequirePackage{xkeyval}[2006/11/18] +\RequirePackage{ifthen} +\RequirePackage{liststructure} +\RequirePackage{tikz}[2007/06/07] +\RequirePackage{pgfmathlog} +\usetikzlibrary{plotmarks} + +\def\prefix{pgfplots} + +\newcount\axisticknum +\newcount\axis@tickposnum +\newcount\axis@xmode +\newcount\axis@ymode +\newcount\axis@numplots +\newdimen\axis@xcoordminTEX +\newdimen\axis@xcoordmaxTEX +\newdimen\axis@ycoordminTEX +\newdimen\axis@ycoordmaxTEX +\newdimen\axis@tmpa +\newdimen\axis@tmpb +\newif\ifaxis@isuniformtick +\let\axis@TMP=\empty +\let\axis@TMPB=\empty + +\def\axis@leftover{} +\def\axis@rightover{} +\def\axisdefaultwidth{240pt} +\def\axisdefaultheight{207pt} + +\listnew{\blackwhiteplotspeclist}{% + mark options={fill=gray},mark=*\\% + mark options={fill=gray},mark=square*\\% + mark options={fill=gray},mark=otimes*\\% + mark=star\\% + mark options={fill=gray},mark=diamond*\\% + loosely dashed,mark options={solid,fill=gray},mark=*\\% + loosely dashed,mark options={solid,fill=gray},mark=square*\\% + loosely dashed,mark options={solid,fill=gray},mark=otimes*\\% + loosely dashed,mark options={solid},mark=star\\% + loosely dashed,mark options={solid,fill=gray},mark=diamond*\\% +} +\listnew{\coloredplotspeclist}{% + blue,mark options={fill=blue!80!black},mark=*\\% + red,mark options={fill=red!80!black},mark=square*\\% + brown!60!black,mark options={fill=brown!80!black},mark=otimes*\\% + black,mark=star\\% + blue,mark options={fill=blue!80!black},mark=diamond*\\% + red,loosely dashed,mark options={solid,fill=red!80!black},mark=*\\% + brown!60!black,loosely dashed,mark options={solid,fill=brown!80!black},mark=square*\\% + black,loosely dashed,mark options={solid,fill=gray},mark=otimes*\\% + blue,loosely dashed,mark=star,mark options=solid\\% + red,loosely dashed,mark options={solid,fill=red!80!black},mark=diamond*\\% +} + + +\listcopy\coloredplotspeclist\to\autoplotspeclist% +%\listcopy\blackwhiteplotspeclist\to\autoplotspeclist% + +%-------------------------------------------------- +% +% MARKERS: +% mark repeat=3,mark phase=2 +% mark options={color=blue,rotate=180} +% ball,ball color=blue +% {*} +% {x} +% {+} +% \usetikzlibrary{plotmarks} +% {-} +% {|} +% {o} +% {asterisk} +% {star} +% {oplus} +% {oplus*} +% {otimes} +% {otimes*} +% {square} +% {square*} +% {triangle} +% {triangle*} +% {diamond} +% {diamond*} +% {pentagon} +% {pentagon*} +% +% LINES: +% line width=2cm +% [snake=zigzag] +% [snake=brace] +% [snake=triangles] +% [snake=coil,segment length=4pt] +% [snake=coil,segment aspect=0] +% [snake=expanding waves,segment angle=7] +% style=solid +% style=dotted +% style=densely dotted +% style=loosely dotted +% style=dashed +% style=densely dashed +% style=loosely dashed +% dash pattern=on 2pt off 3pt on 4pt off 4pt +% dash phase=10pt +% Mit der 'double' und 'double distance' option gibts lustige effekte: +% \draw[draw=white,double=red,very thick] (0,1) -- (1,0); +% \draw[very thick,double distance=2pt] (1,0) arc (180:90:1cm); +%-------------------------------------------------- + +\tikzstyle{every axis}=[] +\tikzstyle{every axis plot}=[] +\tikzstyle{every axis label}=[] +\tikzstyle{every axis x label}=[at={(0.5,0)},below,yshift=-15pt] +\tikzstyle{every axis y label}=[at={(0,0.5)},xshift=-35pt,rotate=90] +\tikzstyle{every tick}=[very thin,gray] +\tikzstyle{every minor tick}=[] +\tikzstyle{every tick label}=[] +\tikzstyle{every x tick label}=[] +\tikzstyle{every y tick label}=[] + +% specifies how and where to draw the axis. +% \tikzstyle{every axis legend}+=[at={(0,0)}] +% will draw it at the lower left corner of the axis while +% \tikzstyle{every axis legend}+=[at={(1,1)}] +% means the upper right corner. +% +% The legend is a 'node' so you can use any tikz option which affects +% nodes. The option 'text width' is set automatically, depending on +% the \legend[textwidth=...] option. +% +% Examples: +% - \tikzstyle{every axis legend}+=[at={(1.02,1)},anchor=north west] +% draws the legend OUTSIDE TOP RIGHT. +% +% - \tikzstyle{every axis legend}+=[at={(1,0.5)},anchor=east,outer sep=0.5cm] +% draws the legend INSIDE MIDDLE RIGHT, separated by 0.5cm from the axis. +\tikzstyle{every axis legend}=[% + anchor=north east,% + shape=rectangle,% + fill=white,% + draw=black, + at={(0.98,0.98)} + ] +% at={(1,1)}, +% outer sep=0.1cm] + + +% +% xticklabel: +% im argument kann man '\axisticknum' und '\tick' verwenden. +% '\tick' ist der eintrag aus '\xtick', der gerade bearbeitet wird, +% '\axisticknum' seine nummer. +% +% yticklabel: +% analog zu xticklabel. +% +% xfilter/yfilter +% \def\meinxfilter#1\to#2{\def#2{1.4}} +% xfilter=\meinxfilter +% +% if the filtered coordinate is empty string, it will be skipped. +\define@cmdkeys[\prefix]{axis}[axis@]{% + xmin,xmax,xticklabel,xtick,xtickten,xlabel,% + ymin,ymax,yticklabel,ytick,ytickten,ylabel,% + trimxmin,trimxmax,trimymin,trimymax,% + subtickwidth,tickwidth,% + xfilter,yfilter,% + width,height,% + execute at begin plot,% + execute at end plot,% + x,y}% + +% sets \axis@tickposnum to +% left=0 +% right=1 +% both=2 +\define@choicekey[\prefix]{axis}{tickpos}[\val\nr]{left,right,both}{% + \axis@tickposnum=\nr\relax +} +\define@boolkeys[\prefix]{axis}[axis@]{% + xminorticks,% + yminorticks,% + disablelogfilter,% + enlargelimits}[true] + +% sets \axis@xmode to +% normal=0 +% log=1 +\define@choicekey[\prefix]{axis}{xmode}[\val\nr]{normal,log}{% + \axis@xmode=\nr\relax +} + +% sets \axis@ymode to +% normal=0 +% log=1 +\define@choicekey[\prefix]{axis}{ymode}[\val\nr]{normal,log}{% + \axis@ymode=\nr\relax +} + +% Options to legend: +% textwidth=auto +% textwidth=none +% textwidth=DIMENSION +\define@cmdkey[\prefix]{legend}[axis@legend@]{textwidth}[auto]{}% + +\define@cmdkey[\prefix]{legend}[axis@legend@]{font}[]{} + +\long\def\axispreset#1{% + \presetkeys[\prefix]{axis}{#1}{}% +} +\long\def\legendpreset#1{% + \presetkeys[\prefix]{legend}{#1}{}% +} + +\presetkeys[\prefix]{axis}{% + xmode=normal, + xmin=, + xmax=, + trimxmin=, + trimxmax=, + xlabel=, + xtick=, + xtickten=, + xticklabel=, + xminorticks=true, + ymode=normal, + ymin=, + ymax=, + trimymin=, + trimymax=, + ylabel=, + ytick=, + ytickten=, + yticklabel=, + yminorticks=true, + tickpos=both, + xfilter=, + yfilter=, + width=, + height=, + subtickwidth=0.1cm, + tickwidth=0.15cm, + x=,% is implicitly set by 'width' and/or '\axisdefaultwidth' + y=,% is implicitly set by 'height' and/or '\axisdefaultheight' + execute at begin plot=,% + execute at end plot=,% + enlargelimits=false, + disablelogfilter=false}{} + +\presetkeys[\prefix]{legend}{% + textwidth=auto, + font=}{} + + +\def\logten{2.302585} + +\newcommand{\logi}[1]{% + \ifcase#1 + \or0 + \or0.693147 + \or1.098612 + \or1.386294 + \or1.60943791 + \or1.7917594 + \or1.94591014 + \or2.07944154 + \or2.197224 + \fi +} + +\newcommand{\show@yticklabel}[2]{{% + \let\ticknum=#1% + \def\tick{#2}% + \axis@yticklabel +}} + +% x-Achsenbeschriftung zum #1.ten Tick: +% #1: die ticknum +% #2: der x wert dafuer +\newcommand{\show@xticklabel}[2]{{% + \let\ticknum=#1% + \def\tick{#2}% + \axis@xticklabel +}} + +\newcommand{\axisdefaultticklabel}[0]{% + $\tick$% +} + +\newcommand{\axisdefaultticklabellog}[0]{% + $10^{\logtologten\tick}$% +} + + +\newcommand{\showxlabel}{% + \node + [style=every axis label,% + style=every axis x label] + {\axis@xlabel}; +} +\newcommand{\showylabel}{% + \node + [style=every axis label, + style=every axis y label] + {\axis@ylabel}; +} + +% Y-Achsen und Achsenbeschriftung LOG: +% 1: Ticks +\newcommand{\yachse}[1]{% + \axisticknum=0 + \foreach \y in {#1} { + %\pgfextracty{\axis@tmpa}{\pgfpointxy{0}{\logten*\y}}% + \pgfextracty{\axis@tmpa}{\pgfpointxy{0}{\y}}% + % + \ifdim\axis@tmpa<\axis@ycoordminTEX + \else + \ifdim\axis@tmpa>\axis@ycoordmaxTEX + \else + % Achsenbeschriftung: + \ifnum\axis@tickposnum=1 + \node at + (\axis@xcoordmaxTEX\axis@leftover,\axis@tmpa) + [right,style=every tick label,style=every y tick label] + {\show@yticklabel\axisticknum\y}; + \else + \node at + (\axis@xcoordminTEX\axis@leftover,\axis@tmpa) + [left,style=every tick label,style=every y tick label] + {\show@yticklabel\axisticknum\y}; + \fi + \global\advance\axisticknum by1 + \fi + \fi + \begin{scope} + \clip (\axis@xcoordminTEX\axis@leftover, \axis@ycoordminTEX\axis@leftover) + rectangle (\axis@xcoordmaxTEX\axis@rightover, \axis@ycoordmaxTEX\axis@rightover); + % Y-Achsenticks links und rechts + % in log: + % beachte: log( i*10^k ) = log\i + k\log10 -> male ticks für i=1..9 + \ifaxis@yminorticks + \foreach \i in {1,...,9} { + \pgfextracty{\axis@tmpb}{\pgfpointxy{0}{\logi\i}}% + \advance\axis@tmpa by\axis@tmpb + \draw[style=every tick,style=every minor tick] + \ifcase\axis@tickposnum + (\axis@xcoordminTEX\axis@leftover, \axis@tmpa) + -- (\axis@xcoordminTEX+\axis@subtickwidth, \axis@tmpa) + \or + (\axis@xcoordmaxTEX\axis@rightover, \axis@tmpa) + -- (\axis@xcoordmaxTEX-\axis@subtickwidth, \axis@tmpa) + \or + (\axis@xcoordminTEX\axis@leftover, \axis@tmpa) + -- (\axis@xcoordminTEX+\axis@subtickwidth, \axis@tmpa) + + (\axis@xcoordmaxTEX\axis@rightover, \axis@tmpa) + -- (\axis@xcoordmaxTEX-\axis@subtickwidth, \axis@tmpa) + \fi + ; + }% + \fi + \draw[style=every tick] + \ifcase\axis@tickposnum + (\axis@xcoordminTEX\axis@leftover,\axis@tmpa) + -- (\axis@xcoordminTEX+\axis@tickwidth,\axis@tmpa) + \or + (\axis@xcoordmaxTEX\axis@rightover,\axis@tmpa) + -- (\axis@xcoordmaxTEX-\axis@tickwidth,\axis@tmpa) + \or + (\axis@xcoordminTEX\axis@leftover,\axis@tmpa) + -- (\axis@xcoordminTEX+\axis@tickwidth,\axis@tmpa) + (\axis@xcoordmaxTEX\axis@rightover,\axis@tmpa) + -- (\axis@xcoordmaxTEX-\axis@tickwidth,\axis@tmpa) + \fi + ; + \end{scope} + } +} + +% X-Achsen und Achsenbeschriftung +% 1: Ticks +\newcommand{\xachse}[1]{% + \axisticknum=0 + \foreach \x in {#1} { + % \pgfextractx{\axis@tmpa}{\pgfpointxy{\logten*\x}{0}}% + \pgfextractx{\axis@tmpa}{\pgfpointxy{\x}{0}}% + % + \ifdim\axis@tmpa<\axis@xcoordminTEX + \else + \ifdim\axis@tmpa>\axis@xcoordmaxTEX + \else + % Achsenbeschriftung: + \ifnum\axis@tickposnum=1 + \node at + (\axis@tmpa,\axis@ycoordmaxTEX\axis@leftover) + [above,style=every tick label,style=every x tick label] + {\show@xticklabel\axisticknum\x}; + \else + \node at + (\axis@tmpa,\axis@ycoordminTEX\axis@leftover) + [below,style=every tick label,style=every x tick label] + {\show@xticklabel\axisticknum\x}; + \fi + \global\advance\axisticknum by1 + \fi + \fi + + \begin{scope} + \clip (\axis@xcoordminTEX\axis@leftover, \axis@ycoordminTEX\axis@leftover) + rectangle (\axis@xcoordmaxTEX\axis@rightover, \axis@ycoordmaxTEX\axis@rightover); + % Y-Achsenticks links und rechts + % in log: + % beachte: log( i*10^k ) = log\i + k\log10 -> male ticks für i=1..9 + \ifaxis@xminorticks + \foreach \i in {1,...,9} { + \pgfextractx{\axis@tmpb}{\pgfpointxy{\logi\i}{0}}% + \advance\axis@tmpa by\axis@tmpb + \draw[style=every tick,style=every minor tick] + \ifcase\axis@tickposnum + (\axis@tmpa, \axis@ycoordminTEX\axis@leftover) + -- (\axis@tmpa, \axis@ycoordminTEX+\axis@subtickwidth) + \or + (\axis@tmpa, \axis@ycoordmaxTEX\axis@rightover) + -- (\axis@tmpa, \axis@ycoordmaxTEX-\axis@subtickwidth) + \or + (\axis@tmpa, \axis@ycoordminTEX\axis@leftover) + -- (\axis@tmpa, \axis@ycoordminTEX+\axis@subtickwidth) + + (\axis@tmpa, \axis@ycoordmaxTEX\axis@rightover) + -- (\axis@tmpa, \axis@ycoordmaxTEX-\axis@subtickwidth) + \fi + ; + }% + \fi + \draw[style=every tick] + \ifcase\axis@tickposnum + (\axis@tmpa, \axis@ycoordminTEX\axis@leftover) + -- (\axis@tmpa, \axis@ycoordminTEX+\axis@tickwidth) + \or + (\axis@tmpa, \axis@ycoordmaxTEX\axis@rightover) + -- (\axis@tmpa, \axis@ycoordmaxTEX-\axis@tickwidth) + \or + (\axis@tmpa, \axis@ycoordminTEX\axis@leftover) + -- (\axis@tmpa, \axis@ycoordminTEX+\axis@tickwidth) + (\axis@tmpa, \axis@ycoordmaxTEX\axis@rightover) + -- (\axis@tmpa, \axis@ycoordmaxTEX-\axis@tickwidth) + \fi + ; + \end{scope} + } +} + +\def\axis@rememberplotspec#1{{% + \globaldefs=1 + \listpushback#1\to\axis@plotspeclist + \advance\axis@numplots by1% +}} + +\def\axis@getautoplotspec into#1{% + \listsize\autoplotspeclist\to\c@pgf@counta + \ifnum\c@pgf@counta=0 + \let#1=\empty + \else + \c@pgf@countb=\axis@numplots + \loop + \ifnum\c@pgf@countb<\c@pgf@counta + \else + \advance\c@pgf@countb by-\c@pgf@counta + \repeat + \listselect\c@pgf@countb\of\autoplotspeclist\to#1 + %\message{pgfplots.sty: using \string\autoplotspeclist\ specification no\#\the\c@pgf@countb (of \the\c@pgf@counta): #1}% + \fi +} + +% The main interface to draw a plot into an axis. +% +% Usage: +% \addplot +% plot coordinates { +% (0,0) +% (1,1) +% }; +% +% or +% +% \addplot[color=blue,mark=*] +% plot coordinates { +% (0,0) +% (1,1) +% }; +% +% The first syntax will use the next plot specification in the list +% \autoplotspeclist +% and the first will use blue color and * markers. +% +% The linespec. will be used in the legend. +\long\def\addplot{% + \@ifnextchar[{% + \axis@addplotimpl% + }{% + \axis@getautoplotspec into\nextplotspec + % the space after ']' is required here: + % FIXME: + % - \addplot[]plot coordinates is NOT allowed!? + \expandafter\axis@addplotimpl\expandafter[\nextplotspec] + }% +} + +\long\def\axis@addplotimpl[#1] #2;{% + % #2 = plot coordinates {...} + \ifx\csname axis@execute at begin plot\endcsname\empty + \else + \csname axis@execute at begin plot\endcsname + \fi + \axis@rememberplotspec{[#1]} + \ifaxis@filtercoords + % FIXME : FREE THIS VARIABLE: + \axis@filtercoords#2\newplotcmdto\axis@filteredcoordinateplotcmd + \ifaxis@draw@at@end + \expandafter\axis@update@limits\axis@filteredcoordinateplotcmd;% + \fi + \def\axis@TMP{\axispath\draw[style=every axis plot,#1] }% + \expandafter\axis@TMP\axis@filteredcoordinateplotcmd;% + %\tracingmacros=2\tracingcommands=2 + %\tracingmacros=0\tracingcommands=0 + \else + \ifaxis@draw@at@end + \axis@update@limits#2;% + \fi + \axispath\draw[style=every axis plot,#1] #2;% + \fi + \ifx\csname axis@execute at end plot\endcsname\empty + \else + \csname axis@execute at end plot\endcsname + \fi +}% + +\long\def\axis@update@limits plot coordinates #1;{% +%\axis@update@limits@forpoint#1\axis@restinto\axis@TMP + \def\axis@TMP{#1}% + \def\axis@TMPB{ }% + \ifx\axis@TMPB\axis@TMP% FIXME isn't there a better way to exclude spaces!? + \let\axis@TMP=\empty + \fi + \loop + \ifx\axis@TMP\empty + \else + \expandafter\axis@update@limits@forpoint\axis@TMP\axis@restinto\axis@TMP + \ifx\axis@TMPB\axis@TMP% FIXME isn't there a better way to exclude spaces!? + \let\axis@TMP=\empty + \fi + \repeat +} + +% #1: optional white spaces (will be ignored). FIXME is there a better +% way? I could not get \ignorespaces into this ... +\long\def\axis@update@limits@forpoint#1(#2,#3)#4\axis@restinto#5{% + \ifaxis@autocompute@xlim + \pgfmathlog@invoke@expanded\pgfmathmin@{{\axis@xmin}{#2}}% + \let\axis@xmin=\pgfmathresult + \pgfmathlog@invoke@expanded\pgfmathmax@{{\axis@xmax}{#2}}% + \let\axis@xmax=\pgfmathresult + \fi + \ifaxis@autocompute@ylim + \pgfmathlog@invoke@expanded\pgfmathmin@{{\axis@ymin}{#3}}% + \let\axis@ymin=\pgfmathresult + \pgfmathlog@invoke@expanded\pgfmathmax@{{\axis@ymax}{#3}}% + \let\axis@ymax=\pgfmathresult + \fi + \def#5{#4}% + \axis@limits@are@computedtrue +} + +% Filters coordinates and writes a new, modified 'plot coordinates' +% command to macro #2. +\long\def\axis@filtercoords plot coordinates #1\newplotcmdto#2{% + %\edef#2{plot coordinates \verb|}|}% + \let#2=\empty + \def\axis@TMP{#1}% + \def\axis@TMPB{ }% + \ifx\axis@TMPB\axis@TMP% FIXME isn't there a better way to exclude spaces!? + \let\axis@TMP=\empty + \fi + \loop + \ifx\axis@TMP\empty + \else + \expandafter\axis@filter@point\axis@TMP\appendto#2\axis@restinto\axis@TMP + \ifx\axis@TMPB\axis@TMP% FIXME isn't there a better way to exclude spaces!? + \let\axis@TMP=\empty + \fi + \repeat + \edef#2{plot coordinates {#2}}% +} + +% #1: optional white spaces (will be ignored). FIXME is there a better +% way? I could not get \ignorespaces into this ... +\long\def\axis@filter@point#1(#2,#3)#4\appendto#5\axis@restinto#6{% + \ifx\axis@xfilter\empty + \def\axis@filter@tmpx{#2}% + \else + \let\axis@filter@tmpx=\empty + \axis@xfilter#2\to\axis@filter@tmpx\relax + \fi + \ifx\axis@yfilter\empty + \def\axis@filter@tmpy{#3}% + \else + \let\axis@filter@tmpy=\empty + \axis@yfilter#3\to\axis@filter@tmpy\relax + \fi + \ifx\axis@filter@tmpx\empty + \message{NOTE: coordinate (#2,#3) has been dropped because of the x-coordinate filter.}% + \else + \ifx\axis@filter@tmpy\empty + \message{NOTE: coordinate (#2,#3) has been dropped because of the y-coordinate filter.}% + \else + \edef#5{#5 (\axis@filter@tmpx,\axis@filter@tmpy)}% + \fi + \fi + \def#6{#4}% +} + +\long\def\axispath#1;{% + \ifaxis@draw@at@end + \listpushback{#1;}\to\axis@draw@stored@plots% + \else + #1;% + \fi +} + + +% Assigns a legend. +% Syntax: +% \legend{entry 1\\entry2\\entry3} +% or +% \legend[OPTIONS]{entry 1\\entry2\\} +% +% where OPTIONS is +% - textwidth=auto | DIMEN | none +% like +% \legend[textwidth=auto]{entry 1\\entry2\\} +% \legend[textwidth=2cm}{...} +% \legend[textwidth=none}{...} +% +% The option "textwidth=auto" chooses the correct width automatically; +% the option "textwidth=none" does not perform any line breaking and +% "textwidth=DIMEN" uses the fixed dimenion DIMEN for the (total) +% width of the legend. +% +% - font={...} +% \legend[font=\Huge}{...} +\newcommand{\legend}[2][]{ + {% + \globaldefs=1% this will ONLY store the options and the legend into global variables + \setkeys[\prefix]{legend}{#1}% + \def\axis@TMP{#2}% + \ifx\axis@TMP\empty + \else + \listnew\axis@legend{#2}% + \fi + } +} + +\newcommand{\addlegendentry}[1]{% + {% + \globaldefs=1% this will ONLY store the options and the legend into global variables + \listpushback#1\to\axis@legend + }% +} + +\def\getnextlegend{{% + \globaldefs=1 + \listcheckempty\axis@plotspeclist + \iflistempty + \let\axis@curplotlist=\empty + \else + \listpopfront\axis@plotspeclist\to\axis@curplotlist + \fi + % + \listcheckempty\axis@legend + \iflistempty + \let\axis@curlegend=\empty + \else + \listpopfront\axis@legend\to\axis@curlegend + \fi + \advance\axis@numplots by-1 +}} + +\def\axis@setlegendfont{% + \tikz@textfont + \axis@legend@font +} + +% Helper function for \axis@createlegend +% It assigns the TOTAL width of the legend node to +% the dimension register #1 and the option to #2 as macro. +% Arguments: +% #1 a temporary dimension register which will be filled with the +% width. +% #2 a macro name which will be filled with 'text width=XXXX'. +% WARNING: +% this function use the variables +% - \axis@legend@textwidth (from keyval, see above) +% - \axis@TMP +% - \legendCOORDC +% - \legendHSEP +\def\axis@legend@determinewidth\to#1\optionto#2{% + \def\axis@TMP{auto}% + \ifx\axis@legend@textwidth\axis@TMP + % OPTION + % \legend[textwidth=auto] + % + % STEP 1: maximum width legend entries + #1=0cm + \begingroup + \listforeach\axis@legend\as\axis@curlegend{% + \setbox0=\hbox{{% + \pgfutil@selectfont% RESTORE normal fonts (have been resetted by PGF) + \axis@setlegendfont + \axis@curlegend% + }}% + \ifdim\wd0>#1 + \global#1=\wd0 + \fi + }% + \endgroup + % STEP 2: add plot spec width: + \expandafter\axis@tmpb\legendCOORDC + \advance#1 by\axis@tmpb + % STEP 3: hspace between plot spec and legend: + \advance#1 by\legendHSEP + %\advance#1 by1pt% FIXME I don't know why there was to few place!? + \def#2{text width=\the#1,}% + \else + \def\axis@TMP{none}% + \ifx\axis@legend@textwidth\axis@TMP + % OPTION + % \legend[textwidth=none] + % don't make a '\node[text width=XX]' option: + #1=0cm + \def#2{}% + \else + % OPTION + % \legend[textwidth=2cm] + % just use it: + \expandafter#1\axis@legend@textwidth + \def#2{text width=\the#1,}% + \fi + \fi + % +} + +\newcommand\axis@createlegend{% + \listcheckempty\axis@legend + \iflistempty + \else + % + \def\legendHSEP{5pt}% + \def\legendCOORDB{0.3cm}% + \def\legendCOORDC{0.6cm}% + % + \axis@legend@determinewidth\to\pgf@xa\optionto\axis@TMP + % + % + % This code here invokes + % \node[<CONTENTS OF \axis@TMP>, + % ... + % ] + % where \axis@TMP contains a "text width=XXX" option. + %DEBUG: + %\draw[red] (0,0) rectangle (1,1); + \expandafter\node\expandafter[\axis@TMP% + style=every axis legend] + {% + \loop\ifnum0<\axis@numplots + \getnextlegend + \ifx\axis@curlegend\empty + \else + \vbox{% + \noindent + \begin{minipage}[c]{\legendCOORDC}% + \tikz + \expandafter\draw\axis@curplotlist + [mark repeat=2,mark phase=2] + plot coordinates { + (0cm,0cm) + (\legendCOORDB,0cm) + (\legendCOORDC,0cm)};% + \hss + \end{minipage} + %\expandafter\hskip\legendHSEP + \axis@setlegendfont + \axis@curlegend + }% + \fi + \repeat + }; + \fi +} + +% Checks whether the argument to xtick or ytick is a UNIFORM tick +% sequence. +% +% A uniform tick sequence is 0,...,10 and 3,4,5 and -5,-4,-2 but +% NOT 0,2,4 or 4,10. +% +% Furthermore, any NON-integer tick arguments are also assumed to be +% NOT uniform. +% +% INPUT: +% #1: a tick argument (i.e. something which can be put to +% \foreach \x in {#1}) +% +% OUTPUT: +% \axis@isuniformticktrue +% or +% \axis@isuniformtickfalse +% depending on the check. +% This variable will be set globally. +\def\axis@checkisuniformLOGtick#1{% + \begingroup + \global\axis@isuniformticktrue + \newif\ifisfirst + \isfirsttrue + \foreach \x in {#1}{% + \pgfmathlog@invoke@expanded\pgfmathdivide@{{\x}{\logten}}% + \let\cur=\pgfmathresult + % check whether + % \cur - last == 1 (last = \axis@TMPB) + \ifisfirst + \global\isfirstfalse + \else + \pgfmathlog@invoke@expanded\pgfmathsubtract@{{\cur}{\axis@TMPB}}% + \def\axis@TMP{1.0}% + \ifx\axis@TMP\pgfmathresult + \else + \global\axis@isuniformtickfalse + \breakforeach + \fi + \fi + \global\let\axis@TMPB=\cur + }% + \endgroup +} + +\def\skipsuffixzero#1.#2|{ + {% + \def\axis@TMP{#2}% + \def\axis@TMPB{0}% + \ifx\axis@TMP\axis@TMPB + \global\def\pgfmathresult{#1}% + \else + \global\def\pgfmathresult{#1.#2}% + \fi + }% +} + +% Expands to #1/log(10). It will also skip a suffix '.0' +\def\logtologten#1{% + \pgfmathlog@invoke@expanded\pgfmathdivide@{{#1}{\logten}}% + \expandafter\skipsuffixzero\pgfmathresult|% + \pgfmathresult +} + +% helper method which computes log10*\x foreach \x in {#1}. +% The result will be \xdef'ed into #2. +\def\axis@compute@tick@times@logten#1\to#2{% + \global\let#2=\empty + \foreach \axis@TMPB in {#1} {% + \pgfmathlog@invoke@expanded\pgfmathmultiply@{{\axis@TMPB}{\logten}}% + \ifx#2\empty + \xdef#2{\pgfmathresult}% + \else + \xdef#2{#2,\pgfmathresult}% + \fi + }% +} + +\def\axis@enlarge@xlim{% + \ifcase\axis@xmode + \pgfmathlog@invoke@expanded\pgfmathsubtract@{{\axis@xmin}{0.5}}% + \let\axis@xmin=\pgfmathresult + \pgfmathlog@invoke@expanded\pgfmathadd@{{\axis@xmax}{0.5}}% + \let\axis@xmax=\pgfmathresult + \or + % compute + % \pgfmathsetmacro{\axis@xmin}{\axis@xmin - 0.5*\logten}% + % \pgfmathsetmacro{\axis@xmax}{\axis@xmax + 0.5*\logten}% + % just a more efficiently (I hope so): + \expandafter\pgfmath@x\logten pt + \divide\pgfmath@x by2 + \pgfmathlog@invoke@expanded\pgfmathsubtract@{{\axis@xmin}{\pgf@sys@tonumber{\pgfmath@x}}}% + \let\axis@xmin=\pgfmathresult + \pgfmathlog@invoke@expanded\pgfmathadd@{{\axis@xmax}{\pgf@sys@tonumber{\pgfmath@x}}}% + \let\axis@xmax=\pgfmathresult + \fi +} +\def\axis@enlarge@ylim{% + \ifcase\axis@ymode + \pgfmathlog@invoke@expanded\pgfmathsubtract@{{\axis@ymin}{0.5}}% + \let\axis@ymin=\pgfmathresult + \pgfmathlog@invoke@expanded\pgfmathadd@{{\axis@ymax}{0.5}}% + \let\axis@ymax=\pgfmathresult + \or + % compute + % \pgfmathsetmacro{\axis@ymin}{\axis@ymin - 0.5*\logten}% + % \pgfmathsetmacro{\axis@ymax}{\axis@ymax + 0.5*\logten}% + % just a more efficiently (I hope so): + \expandafter\pgfmath@y\logten pt + \divide\pgfmath@y by2 + \pgfmathlog@invoke@expanded\pgfmathsubtract@{{\axis@ymin}{\pgf@sys@tonumber{\pgfmath@y}}}% + \let\axis@ymin=\pgfmathresult + \pgfmathlog@invoke@expanded\pgfmathadd@{{\axis@ymax}{\pgf@sys@tonumber{\pgfmath@y}}}% + \let\axis@ymax=\pgfmathresult + \fi +} + + +\def\axis@determinedefaultvalues{% + % NOTIZ: + % + % wenn ich AUTOMATISCH aus (x_i,y_i) + % [xy]min und [xy]max ausrechnen will, muss ich + % ggf. + % xmin = min_{i} { untere_gaussklammer(log(x_i) / log10) } + % rechnen + % + \ifx\axis@xmin\empty + \errmessage{Sorry, the argument 'xmin=NUM' is mandatory to draw axes }% + \fi + \ifx\axis@xmax\empty + \errmessage{Sorry, the argument 'xmax=NUM' is mandatory to draw axes }% + \fi + \ifx\axis@ymin\empty + \errmessage{Sorry, the argument 'ymin=NUM' is mandatory to draw axes }% + \fi + \ifx\axis@ymax\empty + \errmessage{Sorry, the argument 'ymax=NUM' is mandatory to draw axes }% + \fi + % + % + \ifx\axis@trimxmin\empty + \else + \pgfmathlog@invoke@expanded\pgfmathmax@{{\axis@xmin}{\axis@trimxmin}}% + \let\axis@xmin=\pgfmathresult + \fi + \ifx\axis@trimxmax\empty + \else + \pgfmathlog@invoke@expanded\pgfmathmin@{{\axis@xmax}{\axis@trimxmax}}% + \let\axis@xmax=\pgfmathresult + \fi + \ifx\axis@trimymin\empty + \else + \pgfmathlog@invoke@expanded\pgfmathmax@{{\axis@ymin}{\axis@trimymin}}% + %\pgfmathmax\axis@ymin\axis@trimymin% + \let\axis@ymin=\pgfmathresult + \fi + \ifx\axis@trimymax\empty + \else + \pgfmathlog@invoke@expanded\pgfmathmin@{{\axis@ymax}{\axis@trimymax}}% + %\pgfmathmin\axis@ymax\axis@trimymax% + \let\axis@ymax=\pgfmathresult + \fi + % + % + \ifnum\axis@xmode=0 + \axis@xminorticksfalse + \fi + \ifnum\axis@ymode=0 + \axis@yminorticksfalse + \fi + \ifaxis@enlargelimits + % relax the sizes. + % + % Idea: if the user chose his xmin,xmax tight to his data, + % this here will look better. + \axis@enlarge@xlim + \axis@enlarge@ylim + \else + \ifaxis@autocompute@xlim + \axis@enlarge@xlim + \fi + \ifaxis@autocompute@ylim + \axis@enlarge@ylim + \fi + \fi +% + \newif\ifaxis@xisuniform + \newif\ifaxis@yisuniform + \axis@xisuniformtrue + \axis@yisuniformtrue + \newif\ifaxis@needs@check@uniformtick + \axis@needs@check@uniformticktrue + \ifx\axis@xtick\empty + \begingroup + \ifcase\axis@xmode + \pgfmathsetcount{\c@pgf@counta}{\axis@xmin-1}% + \edef\tmp@min{\the\c@pgf@counta}% + \pgfmathsetcount{\c@pgf@counta}{\axis@xmax}% + \edef\tmp@max{\the\c@pgf@counta}% + \xdef\axis@TMP{\tmp@min,...,\tmp@max}% + \aftergroup\axis@needs@check@uniformtickfalse + \or + \ifx\axis@xtickten\empty + % I want ticks at 10^k. So determine k_min and k_max. + \pgfmathsetcount{\c@pgf@counta}{\axis@xmin/\logten-1}% + \pgfmathsetmacro{\tmp@min}{\c@pgf@counta*\logten}% + \pgfmathsetcount{\c@pgf@counta}{\axis@xmax/\logten}% + \pgfmathsetmacro{\tmp@max}{\c@pgf@counta*\logten}% + \pgfmathadd\tmp@min\logten% + \xdef\axis@TMP{\tmp@min,\pgfmathresult,...,\tmp@max}% + \aftergroup\axis@needs@check@uniformtickfalse + \else + \expandafter\axis@compute@tick@times@logten\axis@xtickten\to\axis@TMP + \aftergroup\axis@needs@check@uniformticktrue + \fi + \fi + \endgroup + \let\axis@xtick=\axis@TMP + %\message{pgfplots.sty: xtick set to \axis@xtick [xmode=\the\axis@xmode].}% + \fi + \ifaxis@needs@check@uniformtick + \ifnum\axis@xmode=1 + \expandafter\axis@checkisuniformLOGtick\expandafter{\axis@xtick}% + \fi + \ifaxis@isuniformtick + \axis@xisuniformtrue + \else + \axis@xminorticksfalse + \axis@xisuniformfalse + \fi + \fi + % + % + % + \axis@needs@check@uniformticktrue + \ifx\axis@ytick\empty + \begingroup + \ifcase\axis@ymode + \pgfmathsetcount{\c@pgf@counta}{\axis@ymin-1}% + \edef\tmp@min{\the\c@pgf@counta}% + \pgfmathsetcount{\c@pgf@counta}{\axis@ymax}% + \edef\tmp@max{\the\c@pgf@counta}% + \xdef\axis@TMP{\tmp@min,...,\tmp@max}% + \aftergroup\axis@needs@check@uniformtickfalse + \or + \ifx\axis@ytickten\empty + % I want ticks at 10^k. So determine k_min and k_max. + \pgfmathsetcount{\c@pgf@counta}{\axis@ymin/\logten-1}% + \pgfmathsetmacro{\tmp@min}{\c@pgf@counta*\logten}% + \pgfmathsetcount{\c@pgf@counta}{\axis@ymax/\logten}% + \pgfmathsetmacro{\tmp@max}{\c@pgf@counta*\logten}% + \pgfmathadd\tmp@min\logten% + \xdef\axis@TMP{\tmp@min,\pgfmathresult,...,\tmp@max}% + \aftergroup\axis@needs@check@uniformtickfalse + \else + \expandafter\axis@compute@tick@times@logten\axis@ytickten\to\axis@TMP + \aftergroup\axis@needs@check@uniformticktrue + \fi + \fi + \endgroup + \let\axis@ytick=\axis@TMP + %\message{pgfplots.sty: ytick set to \axis@ytick[ymode=\the\axis@ymode.}% + \fi + \ifaxis@needs@check@uniformtick + \ifnum\axis@ymode=1 + \expandafter\axis@checkisuniformLOGtick\expandafter{\axis@ytick}% + \fi + \ifaxis@isuniformtick + \axis@yisuniformtrue + \else + \axis@yminorticksfalse + \axis@yisuniformfalse + \fi + \fi + \ifx\axis@xticklabel\empty + \ifcase\axis@xmode + \def\axis@xticklabel{\axisdefaultticklabel}% + \or + \def\axis@xticklabel{\axisdefaultticklabellog}% + \fi + \fi + \ifx\axis@yticklabel\empty + \ifcase\axis@ymode + \def\axis@yticklabel{\axisdefaultticklabel}% + \or + \def\axis@yticklabel{\axisdefaultticklabellog}% + %-------------------------------------------------- + % \def\axis@yticklabel{% + % \pgfmathexp\tick + % \expandafter\skipsuffixzero\pgfmathresult|% + % $\pgfmathresult$}% + %-------------------------------------------------- + \fi + \fi +} + +% Helper method for initsizes. +% +% It computes a scaling such that \axis@width = SCALE * ACTUAL WIDTH. +% +% The actual width is +% c + x*(xmax-xmin) +% based on +% - x*xmax = \axis@xcoordmaxTEX +% - x*xmin = \axis@xcoordminTEX +% - c = estimated, a constant for the axis label/tick labels +% +% Arguments: +% #1: the output argument for the SCALE. +\def\axis@initsizes@getXscale\into#1{% + \expandafter\axis@tmpa\axis@width\relax + % EXPECTED WIDTH = X = \axis@width + % ACTUAL WIDTH = c + x * (xmax-xmin) + % where c is a CONSTANT (for the axis labels/tick labels). + % -> \axis@tmpXscale = (X - c) / (x *(xmax-xmin)) + % + % \axis@tmpa := X-c: + \advance\axis@tmpa by-45pt% FIXME determine 'c' correctly! + % \axis@tmpb := x*(xmax-xmin): + \axis@tmpb=\axis@xcoordmaxTEX + \advance\axis@tmpb by-\axis@xcoordminTEX + \pgfmathlog@invoke@expanded\pgfmathdivide@{% + {\pgf@sys@tonumber\axis@tmpa}% + {\pgf@sys@tonumber\axis@tmpb}% + }% + \let#1=\pgfmathresult + %-------------------------------------------------- + % \message{pgfplots.sty: Computing 'x' such that 'width = c + x*(xmax-xmin)'; + % c=estimated, + % width-c =\the\axis@tmpa, + % x*(xmax[=\the\axis@xcoordmaxTEX] - xmin[=\the\axis@xcoordminTEX)]) = \the\axis@tmpb + % -> x-scale =#1 }% + %-------------------------------------------------- +} + +% The same as \axis@initsizes@getXscale, just for the height. +\def\axis@initsizes@getYscale\into#1{% + \expandafter\axis@tmpa\axis@height\relax + % EXPECTED WIDTH = X = \axis@width + % ACTUAL WIDTH = c + x * (xmax-xmin) + % where c is a CONSTANT (for the axis labels/tick labels). + % -> \axis@tmpXscale = (X - c) / (x *(xmax-xmin)) + % + % \axis@tmpa := X-c: + \advance\axis@tmpa by-45pt% FIXME determine 'c' correctly! + % \axis@tmpb := x*(xmax-xmin): + \axis@tmpb=\axis@ycoordmaxTEX + \advance\axis@tmpb by-\axis@ycoordminTEX + \pgfmathlog@invoke@expanded\pgfmathdivide@{% + {\pgf@sys@tonumber\axis@tmpa}% + {\pgf@sys@tonumber\axis@tmpb}% + }% + \let#1=\pgfmathresult + %-------------------------------------------------- + % \message{pgfplots.sty: Computing 'y' such that 'height = c + y*(ymax-ymin)'; + % %height=\axis@height, + % c=estimated, + % height-c =\the\axis@tmpa, + % y*(ymax[=\the\axis@ycoordmaxTEX] - ymin[=\the\axis@ycoordminTEX)]) = \the\axis@tmpb + % -> y-scale =#1 }% + %-------------------------------------------------- +} + +\def\axis@initsizes{% + % INIT. + % + % The axes 'x' and 'y' vectors will be scaled such that the total + % size is (\axisdefaultwidth, \axisdefaultheight). + % + % If the user specifies ONE of width OR height, + % the plot will be resized; keeping the aspect ratio. + \expandafter\pgfmath@x\axisdefaultwidth + \expandafter\pgfmath@y\axisdefaultheight + \pgfmathlog@invoke@expanded\pgfmathdivide@{% + {\pgf@sys@tonumber{\pgfmath@x}}% + {\pgf@sys@tonumber{\pgfmath@y}}% + }% + \let\axis@default@aspect@ratio=\pgfmathresult + % + \pgfpointxy{\axis@xmin}{\axis@ymin}% + \axis@xcoordminTEX=\pgf@x + \axis@ycoordminTEX=\pgf@y + \pgfpointxy{\axis@xmax}{\axis@ymax}% + \axis@xcoordmaxTEX=\pgf@x + \axis@ycoordmaxTEX=\pgf@y + % + %----------------------------------------- + % PROCESS THE 'width' and 'height' options + %----------------------------------------- + % + % FIXME: make these variables LOCAL: + \let\axis@tmpXscale=\empty% + \let\axis@tmpYscale=\empty% + % CASES: + % hasx := 'x' option non-empty + % hasy := 'y' option non-empty + % W := 'width' option non-empty + % H := 'height' option non-empty + % + % hasx hasy + % 0 0 -> work depend on W and H: + % W H + % 0 0 -> use \axisdefaultwidth and \axisdefaultheight + % 0 1 -> determine s:=\axis@tmpYscale and y*=s, x*=s (aspect ratio) + % 1 0 -> determine s:=\axis@tmpXscale and " " " + % 1 1 -> use specified width and height + % 0 1 -> use specified y vector, xscale by 'W' option (NO ASPECT RATIO) + % W + % 0 -> use \axisdefaultwidth + % 1 -> determine s:=\axis@tmpXscale + % 1 0 -> use specified x vector, yscale by 'H' option (NO ASPECT RATIO) + % H + % 0 -> use \axisdefaultheight + % 1 -> determine s:=\axis@tmpYscale + % 1 1 -> use specified x AND y vector (ignore W and H) + % + \ifx\axis@x\empty + \ifx\axis@y\empty + % The case hasx=0, hasy=0, W=0 H=0: + % the other cases for hasx=0, hasy=0 follow below. + \ifx\axis@width\empty\ifx\axis@height\empty + \let\axis@width=\axisdefaultwidth + \let\axis@height=\axisdefaultheight + \fi\fi + \else + % hasx=0, hasy=1, W=0: + \ifx\axis@width\empty + \let\axis@width=\axisdefaultwidth + \fi + \fi + \else + \ifx\axis@y\empty + % hasx=1, hasy=0, H=0 + \ifx\axis@height\empty + \let\axis@height=\axisdefaultheight + \fi + \fi + \fi + % + % common code for the cases if one of W,H is 1: + \ifx\axis@x\empty + \ifx\axis@width\empty + \else + \axis@initsizes@getXscale\into\axis@tmpXscale + \fi + \else + \def\axis@tmpXscale{1}% + \fi + % + \ifx\axis@y\empty + \ifx\axis@height\empty + \else + \axis@initsizes@getYscale\into\axis@tmpYscale + \fi + \else + \def\axis@tmpYscale{1}% + \fi + % + \ifx\axis@x\empty\ifx\axis@y\empty + % hasx=0, hasy=0 and ... + % + % -> KEEP ASPECT RATIO! + % + % CASE W=0 H=1: + \ifx\axis@width\empty + \ifx\axis@height\empty + \else + \expandafter\pgfmath@y\axis@height + \pgfmathlog@invoke@expanded\pgfmathmultiply@{% + {\pgf@sys@tonumber{\pgfmath@y}}% + {\axis@default@aspect@ratio}% + }% + \edef\axis@width{\pgfmathresult pt}% + \axis@initsizes@getXscale\into\axis@tmpXscale + \fi + \else% CASE W=1 H=0: + \ifx\axis@height\empty + \expandafter\pgfmath@x\axis@width + \pgfmathlog@invoke@expanded\pgfmathdivide@{% + {\pgf@sys@tonumber{\pgfmath@x}}% + {\axis@default@aspect@ratio}% + }% + \edef\axis@height{\pgfmathresult pt}% + \axis@initsizes@getYscale\into\axis@tmpYscale + \fi + \fi + \fi\fi + % IMPLEMENTATION NOTE: + % if(Xscale=empty or Yscale=empty) + % -> LOGIC ERROR above. + % + % Apply scaling: + \pgfpointxy{\axis@tmpXscale}{\axis@tmpYscale}% + \axis@tmpa=\pgf@x + \axis@tmpb=\pgf@y + \ifx\axis@x\empty + \pgfsetxvec{\pgfpoint{\axis@tmpa}{0pt}}% + \else + \pgfsetxvec{\pgfpoint{\axis@x}{0pt}}% + \fi + \ifx\axis@y\empty + \pgfsetyvec{\pgfpoint{0pt}{\axis@tmpb}}% + \else + \pgfsetyvec{\pgfpoint{0pt}{\axis@y}}% + \fi + % + \pgfpointxy{\axis@xmin}{\axis@ymin}% + \axis@xcoordminTEX=\pgf@x + \axis@ycoordminTEX=\pgf@y + \pgfpointxy{\axis@xmax}{\axis@ymax}% + \axis@xcoordmaxTEX=\pgf@x + \axis@ycoordmaxTEX=\pgf@y + %----------------------------------------- +} + +\def\axis@BEGIN@init@and@draw@axis{% + \axis@determinedefaultvalues + \axis@initsizes + + % X-Achsenbeschriftung: + % LADE DIE \axis@xtick -variable REIN + \expandafter\xachse\expandafter{\axis@xtick} + % + % Y-Achsen und Achsenbeschriftung: + \expandafter\yachse\expandafter{\axis@ytick}% + + % Äußerer Rahmen: + \draw + (\axis@xcoordminTEX, \axis@ycoordminTEX) + rectangle (\axis@xcoordmaxTEX, \axis@ycoordmaxTEX); + + \begin{scope} + \clip + (\axis@xcoordminTEX, \axis@ycoordminTEX) + rectangle (\axis@xcoordmaxTEX, \axis@ycoordmaxTEX); +} + +\def\axis@END@init@and@draw@axis{% + \end{scope}% +} + +% Writes output to \axis@TMP +\def\axis@filter@input@ticks@with@log#1{% + \let\axis@TMP=\empty + \foreach \axis@TMPB in {#1} {% + \expandafter\pgfmathlog@\expandafter{\axis@TMPB}% + \ifx\axis@TMP\empty + \xdef\axis@TMP{\pgfmathresult}% + \else + \xdef\axis@TMP{\axis@TMP,\pgfmathresult}% + \fi + }% +} + +% In case of (semi-) logplots, this command will +% - assign a filter which invokes \pgfmathlog@{} for each coordinate +% - replace any user-specified coordinate by its log. +% +% All subsequent commands will then work with logarithmic coordinates. +% +% @see pgfmathlog.sty for details about the implementation of log(). +\def\axis@preparelog@filtering{% + \ifnum\axis@xmode=1 + % any user-specified axis limits: + \ifx\axis@xmin\empty + \else + \expandafter\pgfmathlog@\expandafter{\axis@xmin}% + \let\axis@xmin=\pgfmathresult + \fi + \ifx\axis@xmax\empty + \else + \expandafter\pgfmathlog@\expandafter{\axis@xmax}% + \let\axis@xmax=\pgfmathresult + \fi + % + % any user specified axis ticks: + \ifx\axis@xtick\empty + \else + \expandafter\axis@filter@input@ticks@with@log\expandafter{\axis@xtick}% + \edef\axis@xtick{\axis@TMP}% + \fi + \ifx\axis@xfilter\empty + \def\addplot@log@compute@xfilter##1\to##2{% + \pgfmathlog@{##1}% + \let##2=\pgfmathresult + }% + \else + \let\axis@xfilter@orig=\axis@xfilter + \def\addplot@log@compute@xfilter##1\to##2{% + \pgfmathlog@{##1}% + \ifx\pgfmathresult\empty + \let##2=\empty + \else + \expandafter\axis@xfilter@orig\pgfmathresult\to##2\relax + \fi + }% + \fi + \def\axis@xfilter{\addplot@log@compute@xfilter}% + \fi + % + \ifnum\axis@ymode=1 + % any user-specified axis limits: + \ifx\axis@ymin\empty + \else + \pgfmathlog@\expandafter{\axis@ymin}% + \let\axis@ymin=\pgfmathresult + \fi + \ifx\axis@ymax\empty + \else + \pgfmathlog@\expandafter{\axis@ymax}% + \let\axis@ymax=\pgfmathresult + \fi + % + % any user specified axis ticks: + \ifx\axis@ytick\empty + \else + \expandafter\axis@filter@input@ticks@with@log\expandafter{\axis@ytick}% + \edef\axis@ytick{\axis@TMP}% + \fi + \ifx\axis@yfilter\empty + \def\addplot@log@compute@yfilter##1\to##2{% + \pgfmathlog@{##1}% + \let##2=\pgfmathresult + }% + \else + \let\axis@yfilter@orig=\axis@yfilter + \def\addplot@log@compute@yfilter##1\to##2{% + \pgfmathlog@{##1}% + \ifx\pgfmathresult\empty + \let##2=\empty + \else + \expandafter\axis@yfilter@orig\pgfmathresult\to##2\relax + \fi + }% + \fi + \def\axis@yfilter{\addplot@log@compute@yfilter}% + \fi +} + +\newenvironment{axis}[1][]{% + \begingroup + \begin{scope}[style=every axis] +%-------------------------------------------------- +% \draw[very thin,color=gray,xstep=1,ystep=\logten] +% (\xcoordmin\axis@leftover,\ycoordmin) +% grid (\xcoordmax\axis@rightover,\ycoordmax); +%-------------------------------------------------- + \setkeys[\prefix]{axis}{#1}% + \setkeys[\prefix]{legend}{}% + % + \listnewempty\axis@plotspeclist + \listnewempty\axis@legend + \listnewempty\axis@draw@stored@plots + % + \ifaxis@disablelogfilter + \else + \axis@preparelog@filtering + \fi + % + \newif\ifaxis@filtercoords + \ifx\axis@xfilter\empty + \else + \axis@filtercoordstrue + \fi + \ifx\axis@yfilter\empty + \else + \axis@filtercoordstrue + \fi + % + \axis@numplots=0 + % + \newif\ifaxis@autocompute@xlim + \newif\ifaxis@autocompute@ylim + \newif\ifaxis@draw@at@end + \newif\ifaxis@limits@are@computed + \axis@limits@are@computedtrue + \ifx\axis@xmin\empty + \axis@autocompute@xlimtrue + \def\axis@xmin{16300}% + \fi + \ifx\axis@xmax\empty + \axis@autocompute@xlimtrue + \def\axis@xmax{-16300}% + \fi + \ifx\axis@ymin\empty + \axis@autocompute@ylimtrue + \def\axis@ymin{16300}% + \fi + \ifx\axis@ymax\empty + \axis@autocompute@ylimtrue + \def\axis@ymax{-16300}% + \fi + % + \ifaxis@autocompute@xlim + \axis@draw@at@endtrue + \axis@limits@are@computedfalse + \fi + \ifaxis@autocompute@ylim + \axis@draw@at@endtrue + \axis@limits@are@computedfalse + \fi + % + % + \ifaxis@draw@at@end + \else + \axis@BEGIN@init@and@draw@axis + \fi +}{% + \ifaxis@draw@at@end + \ifaxis@limits@are@computed + \else + % EMPTY AXIS: + \def\axis@xmin{0}% + \def\axis@xmax{1}% + \def\axis@ymin{0}% + \def\axis@ymax{1}% + \fi + \axis@BEGIN@init@and@draw@axis + \listforeach\axis@draw@stored@plots\as\plotcmd{\plotcmd}% + \fi + \axis@END@init@and@draw@axis + % + \begin{scope}[% + xshift=+\axis@xcoordminTEX, + yshift=\axis@ycoordminTEX, + x={\axis@xcoordmaxTEX-\axis@xcoordminTEX}, + y={\axis@ycoordmaxTEX-\axis@ycoordminTEX} + ]% + \showxlabel + \showylabel + \axis@createlegend + \end{scope}% + % + \end{scope}% + \endgroup +} + +\newenvironment{semilogxaxis}[1][]{% + \begin{axis}[xmode=log,ymode=normal,#1] +}{% + \end{axis}% +} + +\newenvironment{semilogyaxis}[1][]{% + \begin{axis}[xmode=normal,ymode=log,#1] +}{% + \end{axis}% +} + +\newenvironment{loglogaxis}[1][]{% + \begin{axis}[xmode=log,ymode=log,#1] +}{% + \end{axis}% +} |