Sruthy
Sruthy

Reputation: 27

I couldn't plot graph using matplotlib values from file

I want to plot ECG graph using matplotlib . y values from a file having float values and x value is incrementing(ie x ranges from 1 to 1000). went through tutorials and couldn't find any solutions.

Upvotes: 1

Views: 318

Answers (3)

Anil_M
Anil_M

Reputation: 11473

Demo Code

import numpy as np
import matplotlib.pyplot as plt
import random
import pickle


#Y Axis : Generate 1000 random numbers
yAxisNumbers = np.random.uniform(1,100,1000)

#Save numbers to a file for demo purpose
with open('numpyData.txt', 'wb') as myFile:
    pickle.dump(yAxisNumbers,myFile)


#X Axis :Generate 1000 random numbers
xNumbers = [ x for x in range(1000)]

#Load file data to a list
with open('numpyData.txt', 'rb') as aFile:
    yNumbers = pickle.load(aFile)

#Plot and label Graph
plt.plot(xNumbers,yNumbers)
plt.ylabel("Random Float Numbers")
plt.xlabel("Number Count")
plt.title("ECG Graph")
plt.show()

Graph

enter image description here

Upvotes: 1

Dr. Andrew
Dr. Andrew

Reputation: 2621

Here's a minimal answer, based on the scant details provided.

import numpy as np
import matplotlib.pyplot as plt
plt.ion()

Y = np.loadtxt(filename, other needed options)
plt.plot(np.arange(len(Y))+1,Y)

Upvotes: 1

roadrunner66
roadrunner66

Reputation: 7941

import numpy as np
import pylab as p

aa=np.loadtxt('....your file  ....')
x,y= aa.T  # transpose data into 2 columns, assuming you have 2 columns
p.plot(x,y)
p.show()

Upvotes: 0

Related Questions