网络编程
位置:首页>> 网络编程>> Python编程>> python 使用matplotlib 实现从文件中读取x,y坐标的可视化方法

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

作者:小明37  发布时间:2023-07-29 05:25:42 

标签:python,matplotlib,坐标,可视化

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坐标的可视化方法

来源:https://blog.csdn.net/we1583004we/article/details/79849529

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com