python 使用matplotlib 实现从文件中读取x,y坐标的可视化方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

python 使用matplotlib 实现从文件中读取x,y坐标的可视化方法

  2021-04-03 我要评论

1. test.txt文件,数据以逗号分割,第一个数据为x坐标,第二个为y坐标,数据如下:1.1,2

2.1,2
3.1,3
4.1,5
40,38
42,41
43,42

2. python部分代码

#!/usr/bin/python
# coding: utf-8
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'

x, y = np.loadtxt('test.txt', delimiter=',', unpack=True)
plt.plot(x, y, '*', label='Data', color='black')

plt.xlabel('x')
plt.ylabel('y')
plt.title('Data')
plt.legend()
plt.show()

3. 显示效果

以上这篇python 使用matplotlib 实现从文件中读取x,y坐标的可视化方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们