0

I want to create a Full 12 Leads EKG graph by using matplotlib in Python 2.7, so I had already wrote down some code to represent each lead (using subplot), but it have an issue about drawing a grid on sub-graph. Then I try to find a new solution to ploy all 12 leads within the same graph like this picture below

enter image description here

I have the list of data like this....

x = [1,2,3,4,5,....]
lead1 = [-39,-34,-36,-38,.... ]
lead2 = [-40,-44,-86,-28,.... ]
.
.
lead12 = [-30,-27,-80,-69,.... ]

Could you give me some example code or the direction of how to make that.

Thank you very much.

1

1 Answer 1

0

Here is a simple example, where all lines are plotted in the same axes, but offset by 3 units in y direction.

import matplotlib.pyplot as plt
import numpy as np; np.random.seed(1)

s=3
x = np.linspace(0,10,2000)
a = np.sin(np.cumsum((np.random.normal(scale=0.1, size=(len(x), 12))), axis=0))

fig, ax = plt.subplots()
for i in range(a.shape[1]):
    ax.plot(x, a[:,i]+s*i)

labels = ["PG{}".format(i) for i in range(a.shape[1])]
ax.set_yticks(np.arange(0,a.shape[1])*s)
ax.set_yticklabels(labels)
for t, l in zip(ax.get_yticklabels(), ax.lines):
    t.set_color(l.get_color())

plt.show()

enter image description here

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

3 Comments

Thanks sir, I try this one it's good but I have an issue when I used np.sin as your code a = np.sin(np.cumsum((np.random.normal(scale=0.1, size=(len(x), 12))), axis=0)) I was changed to a = np.dstack((nlead1,nlead2,nlead3,nlead4,nlead5,nlead6,nlead7,nlead8,nlead9,nlead10,nlead11,nlead12)) the error was occurred like this below ValueError: x and y must have same first dimension Could you give me some suggestion. Thank you again _/_
Error messages can usually be taken seriously. The error tells you that x and y to plot do not have the same length. As e.g. plt.plot([1,2,3],[1.2,1.1]) would not work, because the lists do not have the same length. You need to make sure this to be the case.
So I was changed x = np.linspace(0,200,5500) "5500" is the same amount size of value in each nlead1-12 Not sure the Square Brackets is over or not data = [[[ -39 47 86 ..., -100 -77 -3] [ -34 50 85 ..., -101 -75 -1] [ -36 49 86 ..., -103 -77 -4] ..., [ 0 0 0 ..., 0 0 0] [ 0 0 0 ..., 0 0 0] [ 0 0 0 ..., 0 0 0]]]

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.