0
$\begingroup$

I have some data that inherently describes a phase and would like to plot it in between [0, 2*pi).

When I use ListPlot with the Mod[data, 2*pi] function, it nicely transforms the data and plots it between [0, 2*pi) (first image). However, when I use ListLinePlot, artefacts are introduced that connect the points being wrapped around the circle (second image). Is there a way to eliminate these so that these jumps aren't connected? The actual dataset I have is quite large, so looking for each jump manually is unfortunately out of the questions. Thanks!

data = {{-0.00398448, 0.0353995}, {-0.00582442, 0.0336297}, {-0.00821678, 0.0313288}, {-0.0113276, 0.0283377}, {-0.0153729, 0.0244491}, {-0.0199987, 0.0200038}, {-0.0206339, 0.0193936}, {-0.0270866, 0.0131959}, {-0.033543, 0.00699781}, {-0.0400031, 0.00079947}, {-0.0464668, -0.00539914}}

enter image description here

enter image description here

$\endgroup$
1
$\begingroup$

Use "Mod" with an offset:

ListLinePlot[Mod[data, 2 Pi, -Pi], PlotRange -> All]

enter image description here

$\endgroup$
3
  • $\begingroup$ Hey Daniel! Thanks for your response! From my understanding off the offset in the Mod function, does it not just give a result within the region of the offset? When I use your example with my full dataset, for example, it just shifts the whole curve, including the discontinuities, into the region bound by [-pi, pi]. However, I want to keep all of my data in the [0, 2*pi) region -- just without the artefacts that have been introduced via ListLinePlot vs. ListPlot. $\endgroup$
    – Cameron F.
    Nov 24 '21 at 11:39
  • 1
    $\begingroup$ First, you are right, with an offset the range is shifted by the offset. However, you can not have it both ways. If you specify a range from 0 to 2Pi, then everything is in this region. If anything is above 2Pi will be shifted by -2Pi. What you could do, is to plot the outlier separately and combine the plots. Or you could use different "Mod" for different points. $\endgroup$ Nov 24 '21 at 14:04
  • $\begingroup$ Thank you for the suggestion, the idea of plotting separately and combining is quite clever -- will give that a go! $\endgroup$
    – Cameron F.
    Nov 24 '21 at 14:50

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.