2

I want the line to be drawn above the x-axis. Now the line is drawn first and then the x-axis is plotted. I want to reverse it.

\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            axis lines = center,
            xlabel = \(t\),
            ylabel = {\(\text{Hv}(t)\)},
            ymin=0,
            ymax=1.5,
            every axis plot/.append style={ultra thick},
            tick align=inside
        ]
    \addplot [
        domain=0:5, 
        samples=100, 
        color=red,
    ]
    {1};

    \addplot [
        domain=-5:0, 
        samples=100, 
        color=red,
    ]
    {0};
    \addplot[soldot] coordinates{(0,1)};
    \addplot[holdot] coordinates{(0,0)};
    \end{axis}
\end{tikzpicture}

\end{center}

Line is drawn below the x-axis

Thanks in advance

2 Answers2

2

Notice that the axes in pgfplots are normally drawn below the plot traces.

Your problem is brought by the clipping behavior: all plots are clipped to the coordinate areas by default.

If you look closely:

line at 1

line at 0

in the horizontal axis, you have the line clipped at y=0; so its thickness is half than expected and you also see half of the line of the axes (which is centered on y=0 too).

You can solve that by using clip=false in the option of the axis environment, but, if you want more fine-grained control over clipping, you can do like this (thanks to @Jinwen answer for the MWE):

\documentclass{article}

\usepackage{mathtools} \usepackage{pgfplots}\pgfplotsset{compat=newest} \pgfplotsset{soldot/.style={color=red,only marks,mark=}} \pgfplotsset{holdot/.style={color=red,fill=white,only marks,mark=}}

\begin{document}

\begin{center} \begin{tikzpicture} \begin{axis}[ axis lines = center, xlabel = (t), ylabel = {(\text{Hv}(t))}, ymin=0, ymax=1.5, every axis plot/.append style={ultra thick}, tick align=inside, clip mode = individual, ]

    \addplot [
        domain=0:5,
        samples=100,
        color=red,
    ]
    {1};

    \addplot [
        domain=-5:0,
        samples=100,
        color=red,
        clip = false,
    ]
    {0};
    \addplot[soldot] coordinates{(0,1)};
    \addplot[holdot] coordinates{(0,0)};
    \end{axis}
\end{tikzpicture}

\end{center}

\end{document}

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125
0

You can make the axis invisible by setting ymin to be a small negative value (e.g. -0.01). (I don't know your soldot and holdot styles, below is my guess based on this answer.)

\documentclass{article}

\usepackage{mathtools} \usepackage{pgfplots} \pgfplotsset{soldot/.style={color=red,only marks,mark=}} \pgfplotsset{holdot/.style={color=red,fill=white,only marks,mark=}}

\begin{document}

\begin{center} \begin{tikzpicture} \begin{axis}[ axis lines = center, xlabel = (t), ylabel = {(\text{Hv}(t))}, ymin=-.01, ymax=1.5, every axis plot/.append style={ultra thick}, tick align=inside ]

    \addplot [
        domain=0:5,
        samples=100,
        color=red,
    ]
    {1};

    \addplot [
        domain=-5:0,
        samples=100,
        color=red,
    ]
    {0};
    \addplot[soldot] coordinates{(0,1)};
    \addplot[holdot] coordinates{(0,0)};
    \end{axis}
\end{tikzpicture}

\end{center}

\end{document}

enter image description here

Jinwen
  • 8,518