Tikzpicture: axis parameters

1,059

You nearly had the solution: axis y line=middle, axis x line=middle, does the job. However, the parameters for the axis environment need to be in square brackets [] instead of braces {}:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
    \begin{figure}
        \centering
        \begin{tikzpicture}
            \begin{axis}
                [
                    xmin=0, xmax=6,
                    ymin=0, ymax=6,
                    xlabel={$t$},
                    ylabel={$\rho$},
                    axis y line=middle,
                    axis x line=middle,
                ]
                \addplot [black,domain=0:1, no marks] {6};
                \addplot [black,domain=1:2, no marks] {5};  
                \addplot [black,domain=2:3, no marks] {4};
                \addplot [black,domain=3:4, no marks] {3};
                \addplot [black,domain=4:5, no marks] {2};
                \addplot [black,domain=5:6, no marks] {1};
            \end{axis}
        \end{tikzpicture}
        \caption[some text]   {some text}
        \label{fig:someLabel}
    \end{figure}
\end{document}
Share:
1,059

Related videos on Youtube

Scz
Author by

Scz

Updated on August 01, 2022

Comments

  • Scz
    Scz over 1 year

    I've got a question regarding tikzpictures.

    Unfortantely I can't find a way to position my axis labels right at the end of the axis. Additionally it would be great if the lines would be connected if possible.

    That's my simplified code:

    \documentclass{article}
    \usepackage{pgfplots}
    \begin{document}
        \begin{figure}
            \centering
            \begin{tikzpicture}
                \begin{axis}
                    {
                        xmin=0, xmax=6,
                        ymin=0, ymax=6,
                        xlabel={$t$},
                        ylabel={$\rho$},
                        axis y line=middle,
                        axis x line=middle,
                    }
                    \addplot [black,domain=0:1, no marks] {6};
                    \addplot [black,domain=1:2, no marks] {5};
                    \addplot [black,domain=2:3, no marks] {4};
                    \addplot [black,domain=3:4, no marks] {3};
                    \addplot [black,domain=4:5, no marks] {2};
                    \addplot [black,domain=5:6, no marks] {1};
                \end{axis}
            \end{tikzpicture}
            \caption[some text]   {some text}
            \label{fig:someLabel}
        \end{figure}
    \end{document}
    
    • cfr
      cfr about 6 years
      Welcome! Thanks for providing your code. Could you edit you question to make it copy-paste-compilable? That makes it much more useful as people don't have to guess how to complete it.