pgfplots: メジャーグリッドを削除した後、マイナーグリッド/ティックを復元する

pgfplots: メジャーグリッドを削除した後、マイナーグリッド/ティックを復元する

続く前回の質問0との間では副格子が削除されていることが分かりました。そこで、の内側に0.5追加してみました。grid = minorextra tick style

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
    xtick={0.5,1,...,4.5},
    xmin=0,xmax=5,
    minor x tick num = {1},
    minor x tick style = {line width = 2pt},
    major x tick style = {line width = 2pt},
    xmajorgrids, xminorgrids,
    major x grid style = {dashed,red},
    minor x grid style = {dotted,black},
    extra x ticks={0,5},
    extra tick style={
        grid=minor,
    },]
        \addplot[mark=none,blue] {x^2};
    \end{axis}
\end{tikzpicture}
\end{document}

しかし、その結果は

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

私が必要なのは

  1. 0および5の主要な目盛りを削除します
  2. マイナーチェックマークを付ける0.25

脱線質問

なぜ に小さなチェックマークが付いてい4.75て には付いていないのですか0.25?

答え1

したがって、"逆の順序" で行う必要があります。つまり、通常のティックのスタイルを追加のティックに適用し、その逆も行います。

コードの仕組みに関するコメント。(不要なコードは削除しました。)

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin=0,xmax=5,
        % don't state the `xtick's here, but use just the default and state
        % the `xtick distance'
        xtick distance=0.5,
        minor x tick num={1},
        minor x tick style={line width=2pt},
        xminorgrids,
        minor x grid style={dotted,black},
        % but draw the `extra x ticks' with the values of the former `xtick' ...
        extra x ticks={0.5,1,...,4.5},
        % ... but don't draw any labels (because they are there already and
        % there is no need to draw them twice)
        extra x tick labels={},
        % finally apply the needed style for the extra ticks
        extra tick style={
            tick style={line width=2pt},
            major grid style={dashed,red},
            grid=major,
        },
    ]
        \addplot [mark=none,blue] {x^2};
    \end{axis}
\end{tikzpicture}
\end{document}

上記コードの結果を示す画像

関連情報