This is a follow up to Style to make axis tick label opaque, where a suggestion was made to use the extra y ticks
to specify special tick marks and use extra y tick style
to apply a style to only those tick labels.
I attempted to adapt Jake's answer to the above referenced question and apply that by making -2
not a normal tick, but an extra y tick
:
ytick={-1,1,2,3,4},% Note: -2 not listed here
extra y ticks={-2},%
extra y tick style={draw=none, inner sep=0pt, outer sep=0.3333em, fill=white, text opacity=1},
but this does not seem to have any effect on the y tick label
at -2
:
Code:
\documentclass{article}
\usepackage{pgfplots}
\newcommand{\XMin}{-2.2}%
\newcommand{\XMax}{1.5}%
\pgfkeys{/pgfplots/My Axis Style/.append style={
width=7cm, height=8cm,
xmin=\XMin, xmax=\XMax, ymin=-3.2, ymax=2.5,
axis y line=center,
axis x line=middle,
axis on top=true,
ytick={-1,1,2},
extra y ticks={-2},
extra y tick style={draw=none, inner sep=0pt, outer sep=0.3333em, fill=white, text opacity=1},
}
}
\newcommand*{\AddPlotFunction}{\addplot[smooth, ultra thick, domain=\XMin:\XMax, red] {exp(x)-2} node [left] {$y=e^x-2$}}%
\newcommand*{\AddPlotAsymptote}{\addplot[smooth, thin, domain=\XMin:\XMax, blue] {-2} node [below left] {$y=-2$}}%
\begin{document}
\begin{tikzpicture}
\begin{axis}[My Axis Style]
\AddPlotFunction;
\AddPlotAsymptote;
\end{axis}
\end{tikzpicture}
\end{document}