How to customize tick text in TikZ?
€dit³
A suggestion with pgfplots:
I think, you want something like that...
· One methode is setting extra x ticks
, see "T_0+T_1
"; same game with "K
" by using extra y ticks
.
· Another method is to add special labels as a draw
annotation, see "T_0
", "T_1
" and "T_a
", "T_b
":
If you want to use different tick lenghts for your labels, you could prefer the second method.
The following shows both ways.
\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{backgrounds}
\begin{document}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{tikzpicture}
\pgfmathsetlengthmacro\MajorTickLength{
\pgfkeysvalueof{/pgfplots/major tick length}*0.5}
\pgfmathsetlengthmacro\AxisShift{-4.5pt}
\begin{axis}[
xmin=-0,
xmax=6.0,
ymin=0,
ymax=4.5,
%axis lines=middle,
axis y line=middle,
axis x line=bottom,
axis line style={-, gray},
major tick length=\MajorTickLength,
every tick/.style={gray},
tick align=outside,
y axis line style={xshift=\AxisShift},
every y tick/.style={xshift=\AxisShift},
yticklabel style={xshift=\AxisShift},
x axis line style={yshift=\AxisShift},
every x tick/.style={yshift=\AxisShift},
x tick label style={yshift=\AxisShift, fill=white},
ylabel={\rotatebox{90}{$y(t)$}},
xlabel={$t$},
x label style={at={(ticklabel* cs:0.975)}, inner sep=5pt, yshift=4*\AxisShift, anchor=north},
y label style={at={(ticklabel* cs:0.55)}, inner sep=5pt, xshift=3.5*\AxisShift, anchor=east},
xtick={0,...,6},
ytick={1,...,4},
extra y ticks={0,4.5},
extra y tick labels={0,$K$},
grid=major,
extra x ticks={2},
extra x tick labels={$T_0 + T_1$},
extra x tick style={major tick length=-5.25*\AxisShift, on background layer},
%enlarge y limits={abs=0.4,upper},
]
% Curve
\addplot [domain=1.5:6, samples=222, thick]{9/2 *(1 -exp(3 -2*x)};
% Line 1 as parametric plot
\addplot[dashed, variable=\t, samples=2, thick]({2},{\t}) ;
% Line 2 as table-plot
\addplot[no marks, thick,] table[x=X,y=Y] {
X Y
1.5 0
2 4.5
};
% Some special labels ===================
\begin{pgfonlayer}{foreground}
\foreach \T/\Name in {0.5/T_1, 1.5/T_0, 3.85/T_a, 4.6/T_b} {\edef\temp{\noexpand
\draw [gray, yshift=\AxisShift] (\T,0) -- (\T,2.75*\AxisShift) node[below, text=black, inner sep=2pt]{$\Name$};
}\temp}
\end{pgfonlayer}
% ================================
\end{axis}
\end{tikzpicture}
\end{document}
This does something of that sort. In order for one additional tick not wiping out the previous one, you need to the /.list
key. In order to avoid overlaps, you can use shifts. So altogether
major also at/.list={ 1.5 as $T_0$,
2 as [node style={yshift=-2em}] $T_0 + T_1$},
Full MWE:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\begin{tikzpicture}
\datavisualization[
scientific axes={clean},
all axes = grid,
x axis = {
min value = 0,
ticks = {
major also at/.list={ 1.5 as $T_0$,
2 as [node style={yshift=-2em,alias=pft}] $T_0 + T_1$},
stack
},
label = $t$
},
y axis = {
min value = 0,
ticks = {major = {also at = 4.5 as $K$}},
label = $y(t)$
},
visualize as smooth line/.list = {
curve,
line 1,
line 2
},
line 2 = {style = dashed}
]
data[
set = curve,
format = function
] {
var x : interval[1.5 : 6];
func y = 9/2 * (1 - exp(3 - 2 * \value x));
}
data[set = line 1] {
x, y
1.5, 0
2, 4.5
}
data[set = line 2] {
x, y
2, 4.5
2, 0
};
\draw[very thin] (pft.north) -- ++ (0,1em);
\end{tikzpicture}
\end{document}