if I have a list of phases for a sinusoidal data points and want to make a plot of time vs phase, the plot goes back to 0 after the data is past 2 pi. Is there a way I could manipulate the data so it continues after 2 pi? I'm currently using phase = [i % 2*np.pi for i in phase], but this doesn't work.

This being about phase isn't important though. Lets say I had a list of data:

```
data = [0,1,2,0,1,2,0,1,2]
```

But I didn't want the data to reset to 0 after 2, so I want the data to be:

```
data = [0,1,2,3,4,5,6,7,8,9]
```

# Best How To :

There are a few ways.

If you use `numpy`

, the de-facto standard math and array manipulation library for python, then just use `numpy.unwrap`

.

If you want to do it yourself or for some reason not use numpy you can do this

```
def my_unwrap(phase):
phase_diffs = [phase[i+1] - phase[i] for i in range(len(phases)-1)]
unwrapped_phases = [phase[0]]
previous_phase = phase[0]
for phase_diff in phase_diffs:
if abs(phase_diff) > pi:
phase_diff += 2*pi
previous_phase += phase_diff
unwrapped_phases.append(previous_phase)
return unwrapped
```

Seems to work in basic test cases.