2

I created a graph using tikz, which ranges from -10 to 10 for the xaxis.

The graph has an xtick distance of 2, but I want to change the xtick distance so I get this: -10,-5,0,2...10. From -10 to 0, I want steps of 5, and from 0 to 10, I want steps of 2.

Is this possible to do?

I have added my code as well.

\begin{figure}[!htb]
    \centering
    \begin{tikzpicture}
    \begin{axis}[xmin=-10, xmax = 10,ymin=0,
    xtick distance=2,
    xlabel=$x$,ylabel=$Error$,
    title = {Output Error},
    ]
    \addplot [mark=none,color=orange] table[x=x,y=error,col sep=comma]{./output_error.csv};         
    \end{axis}
    \end{tikzpicture}
\end{figure}

enter image description here

1 Answer 1

2

Welcome to TeX-SE! You can just punch in what you want to get: xtick={-10,-5,0,2,4,...,10}. Obviously I do not have your data file.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[xmin=-10, xmax = 10,ymin=0,
    xtick={-10,-5,0,2,4,...,10},
    xlabel=$x$,ylabel=Error,
    title = {Output Error},
    ]
    \addplot [mark=none,color=orange] {x};
    %table[x=x,y=error,col sep=comma]{./output_error.csv};         
    \end{axis}
    \end{tikzpicture}
\end{document}

output plot

2
  • Thank you for your answer. This did the trick, but in a general case is it still possible to have different xtick distance for different ranges.
    – user94758
    Jul 7, 2019 at 7:21
  • 1
    @user94758 I believe it is possible but do not think that the resulting syntax will be simpler than the above.
    – user121799
    Jul 7, 2019 at 7:25

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.