需要安装matplotlib库,可以用如下命令安装:
pip install matplotlib
txt文本数据如下所示(示例中的每一行内部用空格分开):
100 0.6692215
200 0.57682794
300 0.45037615
400 0.42214713
500 0.45073098
600 0.4728373
700 0.48083866
800 0.3751492
900 0.4249844
1000 0.36427215
1100 0.36209464
1200 0.40490758
1300 0.3774191
1400 0.34719718
1500 0.3648946
1600 0.261855
1700 0.4321903
1800 0.35071397
1900 0.279996
2000 0.30030474
适用于Python3的代码如下所示:
import matplotlib.pyplot as plt
input_txt = 'demo.txt'
x = []
y =

本文介绍了如何在Python3中读取txt文本,通过按行读取和字符串分割处理数据,然后利用matplotlib库绘制折线图。首先确保安装matplotlib,接着展示了一个处理txt数据并绘图的代码示例,最后给出了matplotlib的官方参考资料链接。
&spm=1001.2101.3001.5002&articleId=90111149&d=1&t=3&u=a4205b66f2b54ef39744ecbcd15e5962)
1030

被折叠的 条评论
为什么被折叠?



