1

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.

3 Answers 3

1

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

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

3 Comments

How does this answer improve upon my answer as it relates to the relevant details (getting Y data from a file and plotting on a 1-based incremental x-axis?
I updated code to load data from a file [ guessed missed that part earlier]. My code contains all the requirements end to end, Right from loading float values from a file to plotting incrementally , to displaying graphs as needed by user. It gives sense of completeness and user can test by simply copying the code as opposed to making any changes/ modifications
Your code (after being updated) has all the requirements plus a bunch of extra stuff that is not necessary to answer the question. As the question was posted, my answer already had everything necessary...
1

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)

Comments

0
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()

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.