0

that code works almost fine. What I'm missing is a way to connect the lines in a way that it looks like a steps ...

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

Thanks in advance, Thomas

  • and sorry for that code style ... – Thomas H. Sep 21 '17 at 16:20
4

Like this? Pgfplots documentation, section 4.5.3

enter image description here

\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,const plot, no marks] coordinates {(0,6) (1,5) (2,4) (3,3) (4,2) (5,1)};
%                \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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.