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
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
3 Comments
Dr. Andrew
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?
Anil_M
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
Dr. Andrew
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...
