TikZ でティックテキストをカスタマイズするにはどうすればいいですか?

TikZ でティックテキストをカスタマイズするにはどうすればいいですか?

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$他のチェックを完全に無効にして無視しますalso at = 1.5 as $T_0$:

図1

16行目をalso at = 2 as $T_0 + T_1$次のように変更すると、

図2

では、自動生成された目盛りを無効にしたり、上書きしたりせずに、カスタム目盛りテキストを取得するにはどうすればよいでしょうか。2 番目の質問は、どのようにすれば重ならずに配置することT_0ができるかということです。T_0 + T_1

ご協力とご尽力に心より感謝いたします。

答え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プロット:

あなたは、そういうものを望んでいると思います...

· 1 つの方法は設定ですextra x ticks。「 」を参照してください。 「 」を使用してT_0+T_1「 」と同じゲームを実行します。Kextra y ticks

· 別の方法としては、注釈として特別なラベルを追加することですdraw。「T_0」、「T_1」および「 」T_a、「T_b」を参照してください。

ラベルに異なる目盛りの長さを使用したい場合は、2 番目の方法をお勧めします。

以下に両方の方法を示します。

ここに画像の説明を入力してください

\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}

そしてその結果

結果

関連情報