I have some code that will generate a new plot based on a random number. I'm having issues formatting the tick labels, however.
A few things I want to achieve:
- The y-tick label should always start at \N.
- I would always like 5 major ticks in the x and y axis.
- The gridlines/ticks should stop after the 5th major x/y tick but the axis arrow should continue for a small distance longer.
- The plot is rendering ".1.1" in the bottom left hand corner, which I want to get rid of.
Here is my MWE:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgf}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.11}
\begin{document}
\pgfmathsetmacro\N{random(1,1000)}
\pgfmathsetmacro\HL{random(0.1, 10)}
\begin{tikzpicture}
\begin{axis}[
xmin=0, xmax=5*\HL+0.1*\HL,
ymin=0, ymax=\N+0.1*\N,
restrict y to domain=0:\N,
smooth,
samples = 20,
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
axis lines=middle,
minor tick num=10,
axis line style={-latex},
ticklabel style={font=\tiny,fill=white},
]
\addplot[domain=0:5*\HL] {\N*pow(0.5, x/\HL)};
\end{axis}
\end{tikzpicture}
\end{document}