Quantcast
Channel: Automatically put PGFPlots xtick scale label in x axis label - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Stefan Pinnow for Automatically put PGFPlots xtick scale label in x axis label

$
0
0

Here I present a solution which came up mostly from Christian Feuersänger (the author of PGFPlots), but he allowed me to post it here.

(For the record: I added a Feature Request to the PGFPlots Tracker to implement a simpler interface for that.)

For more details on how the solution works, please have a look at the comments in the code.

% used PGFPlots v1.14\documentclass[border=5pt]{standalone}\usepackage{pgfplots}    \pgfplotsset{        % use this `compat' level or higher to use the "advanced" placing of        % the axis labels        compat=1.3,        % create a new style to move the `tick scale label' to the axis labels        tick scale labels in axis labels/.code={            \pgfkeysgetvalue{/pgfplots/xtick scale label code/.@cmd}\temp            % remember the original value of 'xtick scale label code':            \pgfkeyslet{/pgfplots/xtick scale label code orig/.@cmd}\temp            %            \pgfkeysalso{                % simply remember the value in some global macro:                xtick scale label code/.code={                    \gdef\xTickScale{##1}                },                % now, _modify_ any user-specified value of 'xlabel' by                % appending the tick scale label.                % In order to evaluate this modification AFTER the user                % wrote "xlabel={$x$}", we add it to 'every axis':                every axis/.append style={                    % because we don't need the "binop" in this context just                    % set it to nothing                    tick scale binop={},                    xlabel/.add = {}{                        (\pgfplotsset{xtick scale label code orig=\xTickScale}\,m)                    },                },            }        },    }\begin{document}    \begin{tikzpicture}        \begin{axis}[            % activate/load the created style            tick scale labels in axis labels,            xlabel=$x$,            ylabel=$y$,        ]            \addplot coordinates {                (0.0,0.0)(100,1)(400,2)(10000,0)            };        \end{axis}    \end{tikzpicture}\end{document}

image showing the result of above code


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>