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

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

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

相关文章

Django ImageFiled上传照片并显示的方法

1:首先理解settings.py中 MEDIA_ROOT: MEDIA_URL:这两者之间的关系。 MEDIA_ROOT:就是保存上传图片的根目录,比如说MEIDA_ROOT ="C:...

python-pyinstaller、打包后获取路径的实例

python-pyinstaller、打包后获取路径的实例

使用pyinstaller可以把.py文件打包为.exe可执行文件,命令为: pyinstaller hello.py 打包后有两个文件夹,一个是dist,另外一个是build,可执行文...

运行django项目指定IP和端口的方法

运行django项目指定IP和端口的方法

一、django项目启动命令 默认IP和端口 python manage.py runserver 指定端口 python manage.py runserver 192.1...

浅谈PyQt5中异步刷新UI和Python多线程总结

目前任务需要做一个界面程序,PyQt是非常方便的选择,QT丰富的控件以及python方便的编程。近期遇到界面中执行一些后台任务时界面卡死的情况,解决了在这里记录下。 PyQt PyQt简...

pytorch permute维度转换方法

permute prediction = input.view(bs, self.num_anchors, self.bbox_attrs, in_h, in_w).permut...