
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 = 1.5 as $T_0$,
at = 2 as $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
};
\end{tikzpicture}
\end{document}
at = 2 as $T_0 + T_1$
deshabilitando completamente los otros ticks e ignorando also at = 1.5 as $T_0$
:
Si cambio la línea 16 a also at = 2 as $T_0 + T_1$
lo que obtengo
Entonces, ¿cómo se puede obtener el texto de marca personalizado sin deshabilitar/sobrepintar las marcas generadas automáticamente? La segunda pregunta es ¿cómo se pueden colocar T_0
y T_0 + T_1
colocar sin superponer?
¡Gracias por su ayuda y esfuerzo de antemano!
Respuesta1
Esto hace algo por el estilo. Para que una marca adicional no borre la anterior, necesita la /.list
clave. Para evitar superposiciones, puede utilizar turnos. Así que en total
major also at/.list={ 1.5 as $T_0$,
2 as [node style={yshift=-2em}] $T_0 + T_1$},
MWE completo:
\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}
Respuesta2
€dit³
una sugerencia condiagramas de pgf:
Creo que quieres algo así...
· Se está configurando un método extra x ticks
, consulte " T_0+T_1
"; Mismo juego con " K
" usando extra y ticks
.
· Otro método es agregar etiquetas especiales como draw
anotación, consulte " T_0
", " T_1
" y " T_a
", " T_b
":
Si desea utilizar diferentes longitudes de marca para sus etiquetas, podría preferir el segundo método.
A continuación se muestran ambas formas.
\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}
Respuesta3
Descubrí una posibilidad de resolver esta tarea con un método integrado. [{tick text padding = 'some value some measurement'}]
y clean ticks
haz el truco, mira mi 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 = 1.5 as $T_0$,
also at = 2 as [{tick text padding = 1.5em}] $T_0 + T_1$ % <--- changed !!!!!
},
%stack <--- removed !!!!!
},
label = $t$
},
y axis = {
min value = 0,
ticks = {major = {also at = 4.5 as $K$}},
label = $y(t)$
},
clean ticks, % <--- added !!!!!
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
};
\end{tikzpicture}
\end{document}
y el resultado