0

I have created a 2d numpy array as:

for line in finp:
    tdos = []
    for _ in range(250):
        sdata = finp.readline()
        tdos.append(sdata.split())
    break

tdos = np.array(tdos)

Which results in:

[['-3.463' '0.0000E+00' '0.0000E+00' '0.0000E+00' '0.0000E+00']
 ['-3.406' '0.0000E+00' '0.0000E+00' '0.0000E+00' '0.0000E+00']
 ['-3.349' '-0.2076E-29' '-0.3384E-30' '-0.1181E-30' '-0.1926E-31']
 ..., 
 ['10.594' '0.2089E+02' '0.3886E+02' '0.9742E+03' '0.9664E+03']
 ['10.651' '0.1943E+02' '0.3915E+02' '0.9753E+03' '0.9687E+03']
 ['10.708' '0.2133E+02' '0.3670E+02' '0.9765E+03' '0.9708E+03']]

Now, I need to plot $0:$1 and $0:-$2 using matplotlib, so that the in x axis, I will have:

tdata[i][0] (i.e. -3.463, -3.406,-3.349, ..., 10.708)

,and in the yaxis, I will have:

tdata[i][1] (i.e. 0.0000E+00,0.0000E+00,-0.2076E-29,...,0.2133E+02)

How I can define xaxis and yaxis from the numpy array?

10
  • Perhaps tdos[0:1,0:-2] Commented Apr 21, 2016 at 14:46
  • thanks...but did not get. Can you kindly explain? Commented Apr 21, 2016 at 14:48
  • I interpreted your question as: I want to plot all values from index 0 to index 1 in X, and from index 0 to index -2 in Y. That would be a possible answer. I don't know the significance of $in this context. Commented Apr 21, 2016 at 14:52
  • 1
    unusual, but then you'd do p.plot(tdata[:][0], tdata[:][1]) Commented Apr 21, 2016 at 14:59
  • 1
    another option would be to np.transpose, then just plot [1] vs [0] Commented Apr 21, 2016 at 15:01

1 Answer 1

1

Just try the following recipe and see if it is what you want (two image plot methods followed by the same methods but with cropped image):

import matplotlib.pyplot as plt
import numpy as np

X, Y = np.meshgrid(range(100), range(100))
Z = X**2+Y**2

plt.imshow(Z,origin='lower',interpolation='nearest')
plt.show()

plt.pcolormesh(X,Y,Z)
plt.show()

plt.imshow(Z[20:40,30:70],origin='lower',interpolation='nearest')
plt.show()

plt.pcolormesh(X[20:40,30:70],Y[20:40,30:70],Z[20:40,30:70])
plt.show()

, results in:

imshow

pcolormesh

cropped imshow

cropped pcolormesh

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

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.