0

Hello i know that this way to plot in matlab works:

subplot(2,2,[1, 2])
plot(Tabsauv(:, 2:2:2*Ntracks), Tabsauv(:, 3:2:(2*Ntracks+1)),couleur,'LineWidth',2, 'MarkerSize', 2)
grid('on')
hold on

When Tabasauv is a table of values.

I'm a new beginner in python, I tried to plot this in this way with python but it still not working, any idea?

 80 Ntracks=5
 81 fig= plt.figure()
 82 ax=fig.add_subplot(1,1,1)
 83
 84 data_1=np.array([:,2:2:(2*Ntracks)])
 85 data_2=np.array([:,3:2:(2*Ntracks+1])
 86 points = data[:,2:4]
 87
 88 color = np.sqrt((points**2).sum(axis = 1))/np.sqrt(2.0)
 89 rgb = plt.get_cmap('jet')(color)
 90
 91 ax.scatter(data_1, data_2, color = rgb)
 92 plt.show()

I got this error caus' i don't know how to translate it in python:

    data_1=np.arange([:,2:2:(2*Ntracks)])
                      ^
SyntaxError: invalid syntax

Thank you.

2
  • 2
    You would get an answer very quickly if you just (clearly) stated what you want np.arange([:,2:2:(2*Ntracks)]) to be. As it is, I added numpy and matlab to your tags so you might find someone who knows both (matlab was too many years ago for me). Commented Feb 3, 2014 at 16:22
  • You should read wiki.scipy.org/NumPy_for_Matlab_Users Commented Feb 3, 2014 at 21:21

2 Answers 2

2

In matlab, you can generate arrays with ":". In python, you can create arrays using range() function or using arange (in numpy)

so,

 a = 3:5 

in matlab is just the same as

a = np.arange(3,5) #or
a = np.array(range(3,5))

in Python.

Anyway, you might want to look at this page Link in order to translate you code \ thought patterns from Matlab to Numpy.

Sign up to request clarification or add additional context in comments.

Comments

0

You probably mean

data_1 = data[:,2:(2*Ntracks):2]

instead in your code, and similarly for data_2.

A few more things to note:

  1. In numpy indices start from 0. data[:,1:] will skip the first column. Watch out for off-by-one error when doing the translation.

  2. Slicing works slightly differently. The stride is specified by the last number, which is 2 in the above case, not the middle number (different from the Matlab convention).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.