如何使用matplotlib -pyhton在同一窗口中读取文件来生成多个图
我有两个.txt文件,与它们一起,我想绘制与同一窗口中每个文件相对应的图形。我设法只绘制一个。使用以下代码:
import matplotlib.pyplot as plt
timecap = []
qtd = []
# f = open('dataset.txt', 'r')
for line in open('pkts_by_src.txt', 'r'):
lines = [i for i in line.split(',')]
timecap.append(lines[0])
qtd.append(int(lines[1]))
plt.title("Capture")
plt.xlabel('time cap')
plt.ylabel('qtd')
plt.yticks(qtd)
plt.plot(timecap, qtd, marker='o', c='g')
plt.show()
文件以这种格式:
22:40:16,2
22:40:20,1
22:40:20,2
22:40:23,1
22:40:23,4
22:40:23,6
22:40:23,8
您能给我一个提示吗?我是Python的初学者
I have two .txt files and with them, I would like to plot the graphs corresponding to each file in the same window. I managed to plot only one. Using the code below:
import matplotlib.pyplot as plt
timecap = []
qtd = []
# f = open('dataset.txt', 'r')
for line in open('pkts_by_src.txt', 'r'):
lines = [i for i in line.split(',')]
timecap.append(lines[0])
qtd.append(int(lines[1]))
plt.title("Capture")
plt.xlabel('time cap')
plt.ylabel('qtd')
plt.yticks(qtd)
plt.plot(timecap, qtd, marker='o', c='g')
plt.show()
The file is in this format:
22:40:16,2
22:40:20,1
22:40:20,2
22:40:23,1
22:40:23,4
22:40:23,6
22:40:23,8
Can you give me a tip? I'm a beginner in python
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
尝试使用如图所示的子图函数。调用它使您的图形重复后,最后显示(),您可以查看Matplotlib文档中的特定参数。
Try using the subplot function as shown. After calling it make your graph the repeat, at the end do show(), you can look at the matplotlib documentation for specific parameters.