梅威瑟:
\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$
完全禁用其他刻度并忽略also at = 1.5 as $T_0$
:
also at = 2 as $T_0 + T_1$
如果我将第 16 行改为
那么,如何才能获得自定义刻度文本而不禁用/覆盖自动生成的刻度呢?第二个问题是如何T_0
放置T_0 + T_1
而不重叠?
提前感谢您的帮助和努力!
答案1
这可以起到类似的作用。为了不让一个额外的刻度覆盖前一个刻度,你需要按下键/.list
。为了避免重叠,你可以使用移位。所以总的来说
major also at/.list={ 1.5 as $T_0$,
2 as [node style={yshift=-2em}] $T_0 + T_1$},
完整 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}
答案2
€dit³
一个建议pgf图:
我想,你想要这样的东西……
· 一种方法是设置extra x ticks
,参见“ ”;使用 进行T_0+T_1
与“ ”相同的游戏。K
extra y ticks
· 另一种方法是添加特殊标签作为draw
注释,参见“ T_0
”,“ T_1
”和“ T_a
”,“ T_b
”:
如果您想为标签使用不同的刻度长度,您可能更喜欢第二种方法。
下面显示了两种方式。
\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}
答案3
我发现了一种使用板载方法解决此任务的可能性。[{tick text padding = 'some value some measurement'}]
并clean ticks
采取了措施,请参阅我的 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}
结果