简体   繁体   English

如何在Python中使用Matplotlib绘制多条线图

[英]How to draw multiple line graph by using matplotlib in Python

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. 我想通过在Python 2.7中使用matplotlib创建完整的12条Leads心电图,因此我已经写下了一些代码来表示每条引线(使用子图),但是在子图上绘制网格存在问题。 Then I try to find a new solution to ploy all 12 leads within the same graph like this picture below 然后,我尝试找到一种新的解决方案来利用同一张图中的所有12条线索,如下图所示

在此处输入图片说明

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. 非常感谢你。

Here is a simple example, where all lines are plotted in the same axes, but offset by 3 units in y direction. 这是一个简单的示例,其中所有线都绘制在同一轴上,但在y方向上偏移了3个单位。

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM