pgfplots: Restauración de cuadrículas/marcas menores después de eliminar la cuadrícula principal

pgfplots: Restauración de cuadrículas/marcas menores después de eliminar la cuadrícula principal

Siguientemi pregunta anterior, descubrí que la cuadrícula menor se elimina entre 0y 0.5. Entonces, intenté agregar grid = minordentroextra 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}

pero resulta en esto

ingrese la descripción de la imagen aquí

Lo que necesito es

  1. eliminar las garrapatas principales en 0y 5y
  2. coloque garrapatas menores en0.25

Pregunta digresiva

¿Por qué se coloca una marca menor en 4.75y no en 0.25?

Respuesta1

Entonces tienes que hacer las cosas "al revés". Así que aplique el estilo de los ticks normales a los ticks adicionales y viceversa.

Los comentarios del código sobre cómo funciona. (El código no es necesario y lo eliminé).

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

imagen que muestra el resultado del código anterior

información relacionada