0

I have two a two component data file (called RealData) that i am able to load and plot into python using matplotlib using the following code;

x = RealData[:,0]
y = RealData[:,1]
plt.plot(x,y

the first few lines of the data is

1431.11555,-0.02399
1430.15118,-0.02387
1429.18682,-0.02294
1428.22245,-0.02167
1427.25809,-0.02066
1426.29373,-0.02020
1425.32936,-0.02022
1424.36500,-0.02041
1423.40064,-0.02047
1422.43627,-0.02029
1421.47191,-0.01993
1420.50755,-0.01950
1419.54318,-0.01913
1418.57882,-0.01888
.........

I would like to plot the magnitude to the data so that the y component become positive, something like

 |y| = squareRoot((-0.02399)^2 + (-0.02387)^2 + ... ))

I think this would involve some sort of for loop or while loop, however I am not sure how to construct it. any help?

jojo
  • 41
  • 1
  • 1
  • 9
  • `np.sqrt((y**2).sum())` or `np.linalg.norm(y)` – Stef Feb 04 '21 at 17:12
  • thanks you,I am guessing to keep everything at scale I would have to get the magnitude of both components before plotting? so i did: x-axis = np.sqrt((x ** 2).sum()) , y-axis = np.sqrt((y** 2).sum()) plt.plot(x-axis,y-xais) but the plot is empty, the data does not show – jojo Feb 04 '21 at 17:28
  • you're trying to line-plot a point, try `plt.plot(x-axis,y-xais,'o')` to show the dot – Stef Feb 04 '21 at 17:52
  • Okay i understand thank you. I think I dint word my question clearly, Im trying to plot the magnitude of the data so that the negative plot becomes positive – jojo Feb 04 '21 at 18:17
  • I would like to remove the minus sign in the second component of the data above and then plot again – jojo Feb 04 '21 at 18:39
  • you can just put - sign before y-axis and it will do the job. `plt.plot(x-axis,-y-xais,'bo');plt.grid()`. – Jay Patel Feb 04 '21 at 19:41
  • thank you very much – jojo Feb 05 '21 at 03:25

0 Answers0