How to draw multiple line graph by using matplotlib in Python

a 夏天 提交于 2019-12-25 09:19:32

问题


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

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:


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



来源:https://stackoverflow.com/questions/43075823/how-to-draw-multiple-line-graph-by-using-matplotlib-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!