0

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

0

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}

enter image description here

  • 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 at 7:21
  • @user94758 I believe it is possible but do not think that the resulting syntax will be simpler than the above. – user121799 Jul 7 at 7:25
  • @StefanKottwitz I just copied that from the OP. I hope you apply similar standards to posts by others, and wish you happy downvoting. – user121799 Jul 8 at 5:32
  • @marmot I now see it in the OP code. In your screenshot I saw it first as it hurts the eye. :-) Well, no need to keep my vote, I can revert it but it (technically) requires an edit on your post as a vote is locked in after hours. Feel free to make a minor edit (such as a comment on use of $Error$) and I'm happy to revert my downvote when the lock-in is canceled that way. – Stefan Kottwitz Jul 8 at 9:24
  • Btw. my explaining comment "-1 because I think one should not write $Error$ in math mode italics such as a product of variables." has been deleted (so now it's missing context a bit here). Again, I can revert the -1 vote as that mistake is not yours. As above. – Stefan Kottwitz Jul 8 at 9:39

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.