我有两个文件。Xdata.txt
和Ydata.txt
。每行Xdata
应绘制出的每一行Ydata
。关键是每行中的列数是不同的。例如:
Xdata.txt:
row1: 1 2 3 4 5 6
row2: 1 2 3 4
Ydata.txt:
row1: 1 2 3 4 5 6
row2: 1 2 3 4
我想画
Xdata[row1], Ydata[row1]
Xdata=[row2], Ydata[row2]
在一个图中。请帮我解决这种情况。
试试这个(@jrmylow答案的实现):
输入:
Xdata.txt
1 4 3 6 5 6
1 2 3 7
Ydata.txt
1 2 3 4 5 6
1 2 3 4
import matplotlib.pyplot as plt
with open("Xdata.txt", "r") as xf:
x_list = xf.readlines()
with open("Ydata.txt", "r") as yf:
y_list = yf.readlines()
for (x_line, y_line) in zip(x_list, y_list):
x_data = x_line.split(' ')
y_data = y_line.split(' ')
plt.plot(x_data, y_data)
plt.legend(['first','second'])
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句