当前位置:主页 > 软件编程 > Python代码 >

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

时间:2021-04-18 09:50:42 | 栏目:Python代码 | 点击:

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. 显示效果

您可能感兴趣的文章:

相关文章