2

Assume we have a csv file with a single column. I can plot it with ;

data = np.loadtxt(file)
test = data[:,0]
plot(test)

and it plots test versus the row number (entries). But I want to multiply this row number so that I can plot ;

plot(test,row[i]*25)

I think there should exist a simple way than to arrayize the row number. Any pythonic way to handle this issue ?

1
  • Have a look at numpy.arange. E.g. y = 25 * np.arange(test.size). numpy.indices, numpy.mgrid, numpy.ogrid, numpy.ndindex, and numpy.ndenumerate are similar functions that are also useful to be aware of. Commented Apr 21, 2013 at 19:42

1 Answer 1

4

given a data you can do :

import matplotlib.pyplot as plt

data=[0,2,113,....,19,5]
x_coordinate = [ 25 * i for i in range(len(data)) ]
plt.plot(x_coordinate,data)
plt.show()

you'll have all x label indexes as multiples of 25

or use the numpy array functionality:

x_coordinates = 25 * np.arange(test.size)
Sign up to request clarification or add additional context in comments.

2 Comments

This is OK but it's not vectorised.
If by vectorized you mean using numpy array functionnality, I have edited the answer using the numpy array function x_coordinates = 25 * np.arange(test.size) like Joe Kington suggested you in the 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.