tomzko - 7 months ago 58

Python Question

i have no idea how can i plot scatter with a 2D array of this type:

`a=[[x0,t0],[x1,t1],...,[xn,tn]]`

the plot should be x vs t, maybe instead of doing this with a maplotlib routine be able to reshape a to obtain:

`a=[[x0,x1,...,xn],[t0,t1,...,tn]]`

thanks!

Answer

Assuming your data starts in the format a = [[x0, t0]]:

Split x & t into separate lists, then you can pass them into matplotlib.

```
import matplotlib.pyplot as plt
x = [i[0] for i in a]
t = [i[1] for i in a]
plt.plot(x, t)
```