diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgfplots/pgfplotsplothandlers.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgfplots/pgfplotsplothandlers.code.tex | 205 |
1 files changed, 181 insertions, 24 deletions
diff --git a/Master/texmf-dist/tex/generic/pgfplots/pgfplotsplothandlers.code.tex b/Master/texmf-dist/tex/generic/pgfplots/pgfplotsplothandlers.code.tex index 724f1546e22..961362a1857 100644 --- a/Master/texmf-dist/tex/generic/pgfplots/pgfplotsplothandlers.code.tex +++ b/Master/texmf-dist/tex/generic/pgfplots/pgfplotsplothandlers.code.tex @@ -302,17 +302,109 @@ \def\pgfplotssurveyphaseinputclass{direct} +\def\pgfplotsplothandlers@tikz@with@snap@to@nearest{% + \pgfplothandlerdiscard,% + \pgfplothandlermark,% + \pgfplothandlermarklisted,% + \pgfplothandlerxbar,% + \pgfplothandlerybar,% + \pgfplothandlerxbarinterval,% + \pgfplothandlerybarinterval% +}% + +\def\pgfplotsplothandlers@tikz@std{% + \pgfplothandlerdiscard,% + \pgfplothandlermark,% + \pgfplothandlermarklisted,% + \pgfplothandlerxbar,% + \pgfplothandlerybar,% + \pgfplothandlerxbarinterval,% + \pgfplothandlerybarinterval,% + \pgfplothandlerlineto,% + \pgfplothandlercurveto,% + \pgfplothandlerconstantlineto,% + \pgfplothandlerconstantlinetomarkright,% + \pgfplothandlerconstantlinetomarkmid,% + \pgfplothandlerpolarcomb,% + \pgfplothandlerjumpmarkmid,% + \pgfplothandlerjumpmarkleft,% + \pgfplothandlerjumpmarkright% +}% + +% Defines \pgfplotsretval to be the csname for the BACKUP of plot +% handler #1. +% +% For example: +% \pgfplotsplothandlers@get@tikz@backup@name{\pgfplothandlerlineto} +% will return \pgfplotsretval={\\pgfplothandlerlineto@tikz} +% (up to \escapechar) +\def\pgfplotsplothandlers@get@tikz@backup@name#1{% + \begingroup + %\escapechar=-1 % drop the leading backslash + \expandafter\gdef\expandafter\pgfplotsretval\expandafter{\csname \string#1@tikz\endcsname}% + \pgfmath@smuggleone\pgfplotsretval + \endgroup +}% + +% Takes the CURRENT \tikz@plot@handler and checks if it is an UNPATCHED tikz plot +% handler. If so, it replaced it with the correct patched version. +% +% The motivation is that uf \tikz@plot@handler has been set outside of +% an axis, it will not reflect the most recent changes (which are only +% applied within an axis). +\def\pgfplotsplothandlers@init@map@to@patched@versions{% + % iterate through all tikz plot handlers... + \expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplotsplothandlers@tikz@std}% + \as\pgfplots@loc@TMPa{% + % ... get the name of the backup (see \pgfplotsplothandlers@init) + \expandafter\pgfplotsplothandlers@get@tikz@backup@name\pgfplots@loc@TMPa + \expandafter\ifx\pgfplotsretval\tikz@plot@handler + % AH! \tikz@plot@handler is the same as some backup name! + % Replace it: + \expandafter\let\expandafter\tikz@plot@handler\pgfplots@loc@TMPa + \fi + }% +}% + \def\pgfplotsplothandlers@init{% \def\pgfplotsplothandlers@init@##1{% - \expandafter\def\expandafter##1\expandafter{% - ##1% + \pgfplotsutil@add@to@macro##1{% \let\pgfplotsplothandlersurveydifflen=\pgfplotsplothandlersurveydifflen@snaptonearest \let\pgfplotsplothandlersurveypointattime=\pgfplotsplothandlersurveypointattime@snaptonearest }% }% - \pgfplotsutilforeachcommasep{\pgfplothandlerdiscard,\pgfplothandlerxbar,\pgfplothandlerybar,\pgfplothandlerxbarinterval,\pgfplothandlerybarinterval}\as\pgfplots@loc@TMPa{% + \def\pgfplotsplothandlers@init@@##1{% + % create backup: + % + % if ##1 = \pgfplothandlerlineto, this defines + % \pgfplothandlerlineto@tikz as backup. + \pgfplotsplothandlers@get@tikz@backup@name{##1}% + \expandafter\let\pgfplotsretval=##1% + % + % + % assign more suitable names: + \pgfplotsutil@add@to@macro##1{% + \begingroup + \escapechar=-1 % drop the leading backslash + \edef\pgfplotsplothandlername{\string##1}% + \pgfmath@smuggleone\pgfplotsplothandlername + \endgroup + }% + }% + % Patch all TikZ plot handlers: + % this here also creates backups + \expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplotsplothandlers@tikz@std}% + \as\pgfplots@loc@TMPa{% + \expandafter\pgfplotsplothandlers@init@@\expandafter{\pgfplots@loc@TMPa}% + }% + % + % Patch only selected ones: + \expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplotsplothandlers@tikz@with@snap@to@nearest}% + \as\pgfplots@loc@TMPa{% \expandafter\pgfplotsplothandlers@init@\expandafter{\pgfplots@loc@TMPa}% }% + % + \pgfplotsplothandlers@init@map@to@patched@versions }% % Resets the plot handler routines. @@ -924,12 +1016,12 @@ % \E\ifx\E\pgfplots@current@point@x\E\pgfutil@empty \E\else - \ifpgfplots@xislinear - \E\pgfplotscoordmath{x}{parsenumber}{\E\pgfplots@current@point@x}% - \E\let\E\pgfplots@current@point@x=\E\pgfmathresult - \else - % logs are already parsed (in prepare routine) - \fi + % parse for numbers. Note that this might cause + % unnecessary overhead of logs (which are already + % normalized unless someone provided filters). But do it + % anyway to ensure that filters produce valid output. + \E\pgfplotscoordmath{x}{parsenumber}{\E\pgfplots@current@point@x}% + \E\let\E\pgfplots@current@point@x=\E\pgfmathresult \E\pgfplotscoordmath{x}{if is bounded}{\E\pgfplots@current@point@x}% {}% {% this clears nan, inf and -inf points. @@ -940,12 +1032,8 @@ % \E\ifx\E\pgfplots@current@point@y\E\pgfutil@empty \E\else - \ifpgfplots@yislinear - \E\pgfplotscoordmath{y}{parsenumber}{\E\pgfplots@current@point@y}% - \E\let\E\pgfplots@current@point@y=\E\pgfmathresult - \else - % logs are already parsed (in prepare routine) - \fi + \E\pgfplotscoordmath{y}{parsenumber}{\E\pgfplots@current@point@y}% + \E\let\E\pgfplots@current@point@y=\E\pgfmathresult \E\pgfplotscoordmath{y}{if is bounded}{\E\pgfplots@current@point@y}% {}% {% this clears nan, inf and -inf points. @@ -958,12 +1046,8 @@ % \E\ifx\E\pgfplots@current@point@z\E\pgfutil@empty \E\else - \ifpgfplots@zislinear - \E\pgfplotscoordmath{z}{parsenumber}{\E\pgfplots@current@point@z}% - \E\let\E\pgfplots@current@point@z=\E\pgfmathresult - \else - % logs are already parsed (in prepare routine) - \fi + \E\pgfplotscoordmath{z}{parsenumber}{\E\pgfplots@current@point@z}% + \E\let\E\pgfplots@current@point@z=\E\pgfmathresult \E\pgfplotscoordmath{z}{if is bounded}{\E\pgfplots@current@point@z}% {}% {% this clears nan, inf and -inf points. @@ -1014,7 +1098,7 @@ % for 'v' and 'w' instead of 'u'. quiver/.code={% \let\tikz@plot@handler=\pgfplotsplothandlerquiver - \pgfqkeys{/pgfplots/quiver}{#1}% + \pgfqkeys{/pgfplots/quiver}{quiver legend,#1}% },% quiver/u value*/.initial=0, quiver/v value*/.initial=0, @@ -1022,6 +1106,25 @@ quiver/u value is expr/.initial=0, quiver/v value is expr/.initial=0, quiver/w value is expr/.initial=0, + quiver/quiver legend/.style={ + /pgfplots/legend image code/.code={% + \draw[x=0.6cm,y=0cm,z=0pt,##1, + /pgfplots/quiver/before arrow/.add code={}{ + % quiver is a pgfplots-specific plot-handler. We need to + % fix the additional input data somehow. + % + % this is an *absolute* coordinate, interpreted + % relative to 'x', 'y', 'z' + \def\pgfplots@quiver@u{1}% + \def\pgfplots@quiver@v{1}% + \def\pgfplots@quiver@w{1}% + },% + ] + plot coordinates { + (0cm,0cm) + };% + }% + }, quiver/u filter/.code=, quiver/v filter/.code=, quiver/w filter/.code=, @@ -1380,6 +1483,7 @@ \newif\ifpgfplotsplothandlerhistogram@intervals \newif\ifpgfplotsplothandlerhistogram@cumulative +\newif\ifpgfplotsplothandlerhistogram@density \pgfplotsset{ hist/.code={% \let\tikz@plot@handler=\pgfplotsplothandlerhistogram @@ -1398,6 +1502,9 @@ hist/intervals=true, hist/cumulative/.is if=pgfplotsplothandlerhistogram@cumulative, hist/cumulative/.default=true, + hist/density/.is if=pgfplotsplothandlerhistogram@density, + hist/density/.default=true, + hist/density=false, hist/handler/.style={/tikz/ybar interval}, hist/symbolic coords/.style={% /pgfplots/symbolic coords={hist/data}{A,B,C,D,E,F,G,H,I,J}, @@ -1521,15 +1628,52 @@ \expandafter\pgfplotsplothandlersurveyend@hist@loop\pgfplots@hist@data\pgfplots@EOI \let\pgfplots@hist@data=\relax % + + % Calculate total count + \c@pgf@counta=0 + \pgfplotsarrayforeachungrouped{pgfp@hist}\as\pgfplots@hist@count{% + \advance\c@pgf@counta by\pgfplots@hist@count\relax + \def\pgfplots@loc@TMPa{\pgfplotsarrayset{\pgfplotsarrayforeachindex}\of{pgfp@hist}\to}% + }% + \pgfmathfloatparsenumber{\the\c@pgf@counta}% + \let\pgfp@hist@totalcount=\pgfmathresult + \pgfmathfloatreciprocal@{\pgfp@hist@totalcount}% + \let\pgfp@hist@totalcount@inv=\pgfmathresult + % \ifpgfplotsplothandlerhistogram@cumulative \c@pgf@counta=0 \pgfplotsarrayforeachungrouped{pgfp@hist}\as\pgfplots@hist@count{% \advance\c@pgf@counta by\pgfplots@hist@count\relax \def\pgfplots@loc@TMPa{\pgfplotsarrayset{\pgfplotsarrayforeachindex}\of{pgfp@hist}\to}% - \expandafter\pgfplots@loc@TMPa\expandafter{\the\c@pgf@counta}% + \ifpgfplotsplothandlerhistogram@density + \pgfmathfloatparsenumber{\the\c@pgf@counta}% + \pgfmathfloatmultiply@{\pgfmathresult}{\pgfp@hist@totalcount@inv}% + \pgfmathfloattosci@{\pgfmathresult}% + \expandafter\pgfplots@loc@TMPa\expandafter{\pgfmathresult}% + \else + \expandafter\pgfplots@loc@TMPa\expandafter{\the\c@pgf@counta}% + \fi }% + \fi% + % + %% Density histogram + % Divide count in each bin by (totalcount*range/bins) + \ifpgfplotsplothandlerhistogram@density + \ifpgfplotsplothandlerhistogram@cumulative + \else + \pgfmathfloatmultiply@{\pgfp@hist@totalcount@inv}{\pgfplotsplothandlerhistogram@invh}% + \let\pgfp@hist@totalcount@times@h@inv=\pgfmathresult + \pgfplotsarrayforeachungrouped{pgfp@hist}\as\pgfplots@hist@count{% + \pgfmathfloatparsenumber{\pgfplots@hist@count}% + \pgfmathfloatmultiply@{\pgfmathresult}{\pgfp@hist@totalcount@times@h@inv}% + \pgfmathfloattosci@{\pgfmathresult}% + \def\pgfplots@loc@TMPa{\pgfplotsarrayset{\pgfplotsarrayforeachindex}\of{pgfp@hist}\to}% + \expandafter\pgfplots@loc@TMPa\expandafter{\pgfmathresult}% + }% + \fi \fi % + %% End density histogram \pgfplots@curplot@threedimfalse % \pgfplotsset{/pgfplots/hist/handler}% @@ -1694,6 +1838,7 @@ % % Shared parameters: contour/number/.initial=5, + contour/levels/.initial=, % % % Interface to external tools: @@ -1715,7 +1860,17 @@ contour gnuplot/.style={ contour external={% scanline marks=required, - script={unset surface; set cntrparam levels \pgfkeysvalueof{/pgfplots/contour/number}; set contour; set table \"\outfile\"; splot \"\infile\";}, + script={ + unset surface; + \ifx\thecontourlevels\empty + set cntrparam levels \thecontournumber; + \else + set cntrparam levels discrete \thecontourlevels; + \fi + set contour; + set table \"\outfile\"; + splot \"\infile\"; + }, cmd={gnuplot \"\script\"}, #1,% }, @@ -2311,6 +2466,8 @@ \edef\infile{\pgfplotsplothandlercontourexternal@file.dat}% \edef\outfile{\pgfplotsplothandlercontourexternal@file.table}% \edef\script{\pgfplotsplothandlercontourexternal@file.\pgfkeysvalueof{/pgfplots/contour external/script extension}}% + \edef\thecontourlevels{\pgfkeysvalueof{/pgfplots/contour/levels}}% + \edef\thecontournumber{\pgfkeysvalueof{/pgfplots/contour/number}}% \immediate\openout\w@pgf@writea=\script \immediate\write\w@pgf@writea{\pgfkeysvalueof{/pgfplots/contour external/script}}% \immediate\closeout\w@pgf@writea |