pgfplots: Wiederherstellen des Nebenrasters/der Nebenstriche nach dem Entfernen des Hauptrasters

pgfplots: Wiederherstellen des Nebenrasters/der Nebenstriche nach dem Entfernen des Hauptrasters

Gefolgtmeine vorherige Frage, habe ich festgestellt, dass das Nebengitter zwischen 0und entfernt ist 0.5. Also habe ich versucht, grid = minorinnerhalb hinzuzufügenextra 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}

aber es führt dazu, dass

Bildbeschreibung hier eingeben

Was ich brauche, ist

  1. Entfernen Sie die großen Häkchen bei 0und 5und
  2. Setzen Sie kleine Häkchen bei0.25

Abschweifende Frage

Warum steht bei ein kleines Häkchen 4.75und nicht bei 0.25?

Antwort1

Man muss das Ganze also „umgekehrt“ machen. Man wendet also den Stil der normalen Häkchen auf die zusätzlichen Häkchen an und umgekehrt.

Die Kommentare zum Code erläutern, wie er funktioniert. (Nicht benötigter Code, den ich gelöscht habe.)

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

Bild, das das Ergebnis des obigen Codes zeigt

verwandte Informationen