2

I have the following code:

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot coordinates{(10, 20)(90, 80)(170, -50)(290, 12)(350, 20)(5, -40)};
  \end{axis}
\end{tikzpicture}
\end{document}

These coordinates represent longitude/latitude point on the Earth, but the problem is that the two last points are "wrongly" connected by tikz: I get a line from (350, 20) to (5, -40) but I would like the line to go to the right axis (at 360) and come back from the left (at 0).

Basically, I would like to have a "modulo 360" x-axis. Is there a way to do this using tikz or do I have to split this plots into multiple ones?

3

In order to get the periodic plot, just restrict the plot range to [0,360] by dialing xmin=0 and xmax=360 and add the respective points outside the plot range.

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[xmin=0,xmax=360]
    \addplot coordinates{(-10, 20)(5, -40)(10, 20)(90, 80)(170, -50)(290, 12)(350, 20)(365, -40)};
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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.