0

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!

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

Comments

3

You can use numpy.transpose:

import numpy as np
a=[["x0","t0"],["x1","t1"],["xn","tn"]]

np.transpose(a)
# array([['x0', 'x1', 'xn'],
#        ['t0', 't1', 'tn']], 
#       dtype='<U2')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.