Guest User

Confucius and LaTeX+pgfplots

a guest
Sep 30th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 3.23 KB | None | 0 0
  1. \documentclass{standalone}
  2.  
  3. \usepackage{pgfplots}
  4.  
  5. \newcommand{\getpgfkey}[1]{\pgfkeysvalueof{/pgfplots/#1}}
  6. \newcommand{\xmin}[0]{\getpgfkey{xmin}}
  7. \newcommand{\xmax}[0]{\getpgfkey{xmax}}
  8. \newcommand{\ymin}[0]{\getpgfkey{ymin}}
  9. \newcommand{\ymax}[0]{\getpgfkey{ymax}}
  10.  
  11. \usepgfplotslibrary{groupplots}
  12. \pgfplotsset{
  13. xscalingdown/.style={ %XXX SCALE DOWN
  14.     x coord trafo/.code=\pgfmathparse{##1/(1e#1)},
  15.     xlabel style={
  16.         append after command={
  17.             node [anchor=base west] at (\tikzlastnode.base east) {$\cdot{10^{#1}}$}
  18.         }
  19.     },
  20.     every axis/.append code={%
  21.         \pgfmathresult{\xmax/(1e#1)}\global\let\xmaxSCALED=\pgfmathresult
  22.         \pgfmathresult{\xmin/(1e#1)}\global\let\xminSCALED=\pgfmathresult
  23. %       \pgfmathresult{\ymax}\global\let\ymaxSCALED=\pgfmathresult
  24. %       \pgfmathresult{\ymin}\global\let\yminSCALED=\pgfmathresult
  25.     },
  26. },
  27. xscalingup/.style={ %XXX SCALE UP
  28.     x coord trafo/.code=\pgfmathparse{##1*(1e#1)},
  29.     xlabel style={
  30.         append after command={
  31.             node [anchor=base west] at (\tikzlastnode.base east) {$\cdot{10^{{-1}#1}}$}
  32.         }
  33.     },
  34.     every axis/.append code={%
  35.         \pgfmathresult{\xmax*(1e#1)}\global\let\xmaxSCALED=\pgfmathresult
  36.         \pgfmathresult{\xmin*(1e#1)}\global\let\xminSCALED=\pgfmathresult
  37.         %\pgfmathresult{\ymax}\global\let\ymaxSCALED=\pgfmathresult
  38.         %\pgfmathresult{\ymin}\global\let\yminSCALED=\pgfmathresult
  39.     },
  40. },
  41. yscalingdown/.style={ %YYY SCALE DOWN
  42.     y coord trafo/.code=\pgfmathparse{##1/(1e#1)},
  43.     ylabel style={
  44.         append after command={
  45.             node [rotate=90, anchor=base west] at (\tikzlastnode.base east) {$\cdot{10^{#1}}$}
  46.         }
  47.     },
  48.     every axis/.append code={%
  49.         \pgfmathparse{\ymax/(1e#1)}\global\let\ymaxSCALED=\pgfmathresult
  50.         \pgfmathparse{\ymin/(1e#1)}\global\let\yminSCALED=\pgfmathresult
  51.         %\pgfmathresult{\xmax}\global\let\xmaxSCALED=\pgfmathresult
  52.         %\pgfmathresult{\xmin}\global\let\xminSCALED=\pgfmathresult
  53.     },
  54. },
  55. yscalingup/.style={ %YYY SCALE UP
  56.     y coord trafo/.code=\pgfmathparse{##1*(1e#1)},
  57.     ylabel style={
  58.         append after command={
  59.             node [rotate=90, anchor=base west] at (\tikzlastnode.base east) {$\cdot{10^{{-1}#1}}$}
  60.         }
  61.     },
  62.     every axis/.append code={%
  63.         \pgfmathparse{\ymax*(1e#1)}\global\let\ymaxSCALED=\pgfmathresult
  64.         \pgfmathparse{\ymin*(1e#1)}\global\let\yminSCALED=\pgfmathresult
  65.         %\pgfmathresult{\xmax}\global\let\xmaxSCALED=\pgfmathresult
  66.         %\pgfmathresult{\xmin}\global\let\xminSCALED=\pgfmathresult
  67.     },
  68. },
  69. }
  70.  
  71. \begin{document}
  72. \begin{tikzpicture}
  73. \begin{groupplot}[
  74. group style={
  75.     horizontal sep=0.2cm,
  76.     group size=2 by 1,
  77.     ylabels at=edge left,
  78.     yticklabels at=edge left,
  79. },
  80. ymin=-100, ymax=1300,
  81. xlabel={The label for the x-axis},
  82. ylabel={Some y-values},
  83. xscalingdown=3,
  84. yscalingdown=3,
  85. ]
  86. \nextgroupplot
  87. \addplot coordinates{(2000,1200) (3000,\yminSCALED)};
  88. \filldraw[ultra thick, dashed, blue] (\xminSCALED,\yminSCALED) rectangle (\xmaxSCALED,\ymaxSCALED);
  89. \nextgroupplot
  90. \addplot+ coordinates{(2100,1000) (2800,1200)};
  91. \filldraw[ultra thick, dashed, red] (axis cs:2100,1000) rectangle (axis cs:\xmaxSCALED,1000) node[below, fill=orange] {bla};
  92. %%NOTABLE DIFFERENT OUTPUT when omitting 'axis cs'
  93. \filldraw[ultra thick, dashed, red] (2100,1000) rectangle (axis cs:\xmaxSCALED,1000) node[below, fill=orange] {bla};
  94. \end{groupplot}
  95. \end{tikzpicture}
  96. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment